The absolute state of javascript

The absolute state of javascript

Attached: 59B509D5-5B6E-494B-AF42-4052E73D43E7.jpg (1058x1058, 51K)

Other urls found in this thread:

github.com/getify/You-Dont-Know-JS/blob/master/types & grammar/ch4.md
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus_()
twitter.com/SFWRedditImages

>(+string) to convert string to a number
Meh. That's normal tier esoteric. Javascript can do better than that.

Attached: 26730616_1961979830731749_6346812529605365191_n.jpg (700x681, 96K)

>a shorthand for string -> int casting is bad
Why?

That's an odd way to cast a variable for sure. But Node devs can fix it so it makes more sense, right?

OP's chocolate, so he must be a pajeet. Just remembering to check if he didn't misplace the plus sign is too much for him.

>But Node devs can fix it
No.

'1' + 1 = '11'
Ok, like most languages.

+'1' = 1
Sure, why not. Have a string of additions of semi-compatible types adopt the left type (in this case an implicit number zero), continuing throughout the chain. A bit non-standard, but makes enough sense.

1 + '1' = '11'
Ok, shenanigans. Why would you code the unary operator of type Y to cast into type X, but not have type X + type Y cast yo type X?

50 years from now they will look back at JavaScript and laugh.

What language will they not laugh at?

Why aren't you laughing at JS right now?

Number(arbitraryInput1) + Number(arbitraryInput2)

String(arbitraryInput1) + String(arbitraryInput2)[/code]
Hmmmmmmmm, I wonder what will happen in each case
hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

actually it's string+number vs number+number

Where did I ever imply I'm not laughing at it right now?

JS has tons of flaws, but you're stupid if you think this count as one. How is it any different from:
Integer.parseInt("100") + 5;

for instance? It's just a syntactic sugar that looks odd at a first glance.

Teaching programming to normies was a mistake

No, they're laughing right now.

50 years from now on, they're probably amazed at such a low level language ever existed. I mean you had to WRITE javascript instead of just creating highly abstracted applications with your thoughts via neural interface.

stoi("100") + 5
Oh boy, the absolute state of C++!!!
If you want a decent starting point on the absolute insanity of Javascript, start with the clusterfuck known as "this" keyword and closures. Keep digging until you've gotten sick of the terrible language design decisions goldmine.

('1' - 0) + 1

Team CUM

abnorm

Who are "they"? The Jews?

Don't arrow functions get rid of a lot of the issues with "this"?

I know before that you had to use var that = this and stuff.bind(this) everywhere to get around this being changed into all sorts of nonsense in callbacks.

>neural interface
Why would you do that, when you can just say "Computer, I need a graphic of network packet degradation linked up to ping offsets"? You really think the clusterfuck of twitching neurons stepping on top of each other trying to parse visual and auditory information with previous emotional contexts is going to magically going to start behaving like a supercomputer if you plug electrodes in it at random places.

man, do i hate typing "this." on every other line. Holy shit.

Why would you do that either when you can just write machine code?

>closures
function outerFunc (outerArg)
{
var fuckery = "I put this in my function block scope";

function innerFunc (innerArg)
{
return fuckery + outerArg + innerArg
}

return innerFunc;
}

var sike = outerFunc ("...\n ....");

sike("SIKE, THAT'S THE WRONG SCOPE");


Run this in your web console. :^)

>0b10
genius

var outside = 10;

function noscoped(number)
{
return outside * number;
}
noscoped(3);

Dumb creme poster.

Works as expected.

Yeah, both of those are how closures work, not sure what the point is.

>there’s nothing wrong with an unreclaimed variable in stack
webshitter.

Turbo brainlet, I won't even bother explaining to you how it works.

It doesn’t make it a proper behavior just because that’s how JS works, webshit. There are no excuses.

Why Perl of course

Literally any other language with closures will work like that.

What do you expect from mixing data types? Are you just stupid or have autism?

Actually, in sepples it will simply crash.
#include
#include
#include
using namespace std;


function outerFunc(string outerArg)
{
string fuckery = "I put this in my function block scope";

return [&](string innerArg)->string { return fuckery + outerArg + innerArg;};
}
int main()
{
function sike = outerFunc("...\n ....");
cout

1*string+number;

>sepples
>shitting on C++
>in a javascript thread
What?

I'm sorry, I can't keep up with the dankest Jow Forums memery.

Use a subset of Javascript and never worry.

I hate the language but the bitching is out of control.

When JS does something better than your language it's a really bad sign.

this is the real problem

I don't see the problem

WHY WOULD ADDING A STRING AND AN INT TOGETHER RESULT IN A STRING REEEEEEEEEEEEEEEEEEE

>var that = this
This is awful, you should've always used a real name for "that", fortunately there were few real reasons to do this in the first place, and now that arrow functions are usable everywhere it's pretty much gone.
>stuff.bind(this)
I fail to see the issue here, it's the result of using functions instead of interfaces, I'd rather have this than the Java hell of making up types when functions are enough.
And if you have no interfaces and no bind you'd have to bloat every API with an extra parameter for the given "this".

I've seen "that" and "self" commonly used for this case. But most of the time it was because writing lambdas where you would lose the context of this. I saw it a lot like 5 years ago. Now, not really.

epic

what should a language do if you add string with number?

Refuse to compile.

Halt and catch fire.

if the left hand side is a string, concatenate the string with the text representation of the number
if the left hand side is a number, return a compiler error

it should result in a number

Attached: maxresdefault[1].jpg (1280x720, 46K)

Yeah, you shouldn't add a string and a Number directly.

BUT, if you have two adjacent numbers in such an addition operation you can do math additions and string addition in the same operation. Like:

let stageWidth = this.ul.parentElement.clientWidth; // this returns a number

// then we need to perform an addition operation with numbers inside a string concatenation operation
// perfectly and safely doable, pham
// here currentTranslateXCoord is a string extracted from another string, which includes only number characters, so we can convert it to an integer and use it

this.li[i].style.transform = 'translateX(' + (parseInt(currentTranslateXCoord) + stageWidth) + 'px)';


If you're a brainlet, ofc, this is hard for you. But it's perfectly logical.

this is the only correct answer, there's so much time wasted debugging this shit...

You're braindead and so is OP

if implicit casting is to be used; everything should be cast up. Thus an int becomes a string, string being the larger data type.

That is, provided strings are treated as primitives with implicit casting rules etc

>Ok, like most languages.
wtf no, haskell doesn't do this

throw an error

>what is lexical scoping in FP
Just neck yourself, my dude

Attached: 46a.png (645x729, 97K)

Automatic casting with dynamic typed languages are like this in any language, you'll never find a way that pleases everyone.

1 + +'1'

github.com/getify/You-Dont-Know-JS/blob/master/types & grammar/ch4.md

>(in this case an implicit number zero)
Just fyi, using the plus sign like that is called the "unary plus" operator, it's actually complimentary to the "unary minus" operator (e.g. "-1"), rather than being an addition operator.

developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus_()

The real fuckery with scope is how var works:

for(var i = 0; i < 10; ++i;)
{
var j = 10;
}

console.log(i); //Still in scope
console.log(j); //Still in scope, has last loop value

>but not have type X + type Y cast yo type X?
encoding for example.While writing '+' to add string to number seems very intuitve for us, it is actually quite abstract. '+'
can actually be 'shift X letters' and '-' could be 'truncate' / 'remove last X letters'.

Think about it: how does it come You can add strings and numbers, but can't subtract them? We all know that adding has it's inverse operation in subtraction. But adding strings and numbers violates that. WHY?

Bonus ocaml:
let x = "a" ^ string_of_int my_integer

isn't that because var is based on function scope, not block scope?

"let", introduced in es1.6, is block scope.

Yes, with the caveat that var puts the variable onto the window object in the global scope. Let is great, but if you want your code to be usable by the public you can't really use it.

>I don't understand object lifetimes

Because we already laugh at Perl.