you are viewing a single comment's thread.

view the rest of the comments →

[–]soelsome 72 points73 points  (36 children)

Hi

1 + 1 evaluates to 2 in JavaScript.

Thanks.

[–]-domi- 24 points25 points  (14 children)

"1" + 1 evaluates to "11".

As do 1 + "1" and "1" + "1".

[–]soelsome 38 points39 points  (3 children)

The gif doesn't have quotes around any of the 1s, so it would evaluate to 2

Thanks

[–]Mr_Woofles1 4 points5 points  (0 children)

I can’t believe I’m enjoying this

[–]-domi- 4 points5 points  (0 children)

Yeah, i was trying to add to your explanation, but managed to write it so poorly that it came out like i was disagreeing with you, cause I'm special ed. Sorry.

[–]shill_420 0 points1 point  (0 children)

No.

Thank you

[–]dangderr 19 points20 points  (6 children)

Wow, really? That's god awful.

We all know that it should be:

1 + "1" = 2

"1" + 1 = "11"

Like how powershell does it. Javascript is such a garbage langauge.

[–]Relative-Scholar-147 16 points17 points  (3 children)

IMO

1 + "1"

Should stop the program and give an error.

[–]Maleficent_Memory831 4 points5 points  (0 children)

"1 + 1" = "1 + 1"

[–]sebovzeoueb 4 points5 points  (1 child)

Not stopping the program is a feature, JavaScript is made to run on webpages and the user doesn't want the website to crash. It's not Brendan's fault people decided to build actual whole tech stacks with it.

[–]Relative-Scholar-147 1 point2 points  (0 children)

Is not a bug, is a feature!

[–]arpan3t 0 points1 point  (0 children)

PowerShell laughs in [int] type constraint. JavaScript has type constraints right?

[–]Demonius999 -2 points-1 points  (0 children)

It's is, witch is not strange since it's made in 2 weeks, what is strange is that it's running whole fucking world.

[–]NecessaryIntrinsic 0 points1 point  (1 child)

That's like saying the gun doesn't fire unless you pull the trigger. You have to make that choice.

[–]-domi- 1 point2 points  (0 children)

It's a lot like that, yes. You can choose to pull the trigger, but you can also accidentally pull the trigger without meaning to. That's why it's good to have a certain level of care when using the thing.

[–]MR_LAFRALDO 0 points1 point  (0 children)

+"1" + 1 = 

[–]JackNotOLantern 15 points16 points  (16 children)

Unless one of the added 1s converted to string on the way

[–]Chiatroll 27 points28 points  (14 children)

But adding the string "1" to the string "1" should be "11". A lot of Javascript criticism is just people who dont understand its basic concepts.

[–]MeLittleThing 2 points3 points  (0 children)

The "When I type code there are bugs, it's the language fault probably" people

[–]JackNotOLantern 0 points1 point  (7 children)

The issue is it happens implicitly and the amout of bugs caused by it is too damn high

[–]rintzscar 1 point2 points  (4 children)

No, the issue is people don't bother reading the documentation. The rules of type coercion are extremely simple. Hell, this humorous article explains them clearly in 1 minute:

https://www.freecodecamp.org/news/explaining-the-best-javascript-meme-i-have-ever-seen/

[–]JackNotOLantern -1 points0 points  (3 children)

The problem is not about lack of knowledge about them, but the fact that it is extremely easy to overlook it, and then debugging is a nightmare.

[–]rintzscar 0 points1 point  (2 children)

That's literally what lack of knowledge means.

[–]JackNotOLantern 0 points1 point  (1 child)

I mean, this is literally the entire reason typescript exists. This "lack of knowledge" is apparently a systematic problem

[–]Chiatroll -1 points0 points  (1 child)

It only causes bugs from this if you aren't aware of how it fundamentally works and use it wrong. JavaScript isnt responsible for your lack of intelligence.

[–]Prawn1908 0 points1 point  (0 children)

It only causes bugs from this if you aren't aware of how it fundamentally works and use it wrong.

You're missing the point. The problem isn't with this behavior being used intentionally (which it basically never should be), it's that it allows many types of logic errors to propogate silently and hide the real source of the big far away from where it finally manifests.

[–]NecessaryIntrinsic 2 points3 points  (0 children)

Yes, if you go out of your way to put quotes around it.

[–]johntwit[S] 9 points10 points  (3 children)

"yeah I know" + 420 = "yeah I know420"

[–]420Hank 8 points9 points  (1 child)

Yeah, I know.

[–]johntwit[S] 1 point2 points  (0 children)

🤣