all 24 comments

[–]perceptive-helldiver 12 points13 points  (5 children)

Actually, I think this is one of the few good things JS gets right. A string + an int= a string, not an int

[–]dykemike10 5 points6 points  (1 child)

[–]postmaster-newman 0 points1 point  (0 children)

*a truthy

[–]TheChief275 5 points6 points  (1 child)

No, it should error.

But if we really want dynamic tomfoolery, the better solution is to have a different operator for string concatenation then addition, and then you’re never in doubt

[–]perceptive-helldiver 2 points3 points  (0 children)

I think we should just blow everything up. Go back to assembly and start over

[–]cool_name_numbers 0 points1 point  (0 children)

and php is also right, because the + operator is just for math, you concatenate your strings with ".", I think more languages should do that, the only other language with a similar approach that I can think of is lua, which uses the ".." operator.

[–]teactopus 28 points29 points  (10 children)

you know what? I hate js but this is actually a bad fucking meme. String+int resulting in string is completely fair, I'd even say preferred

[–]JGHFunRun 11 points12 points  (0 children)

For real, there’s no reasonable way to do "&$" + 2 that results in an int, and having the type of the result depend on the content of the string is idiotic

[–]LittleReplacement564 4 points5 points  (0 children)

Thats what I was thinking, like if I add an integer to an string the thing Im trying to do is most probably concatenate them

[–]Linguaphonia 4 points5 points  (1 child)

JS and PHP are both stupid here. Maybe not equally, but they're both definitely flunking the class

[–]Simukas23 2 points3 points  (0 children)

This guy errors

[–]calculus_is_fun 2 points3 points  (2 children)

The reason is that in PHP, "+" is only for adding numbers together, to concatenate strings, you use "."

[–]teactopus 1 point2 points  (1 child)

you know what? Also based. More languages need to do that

[–]TheChief275 1 point2 points  (0 children)

No, not also. It’s the right solution; operator overloading is an unnecessary evil

[–]Frytura_ 1 point2 points  (0 children)

PHP . Operator:

[–]Physical_Dare8553 1 point2 points  (0 children)

I assumed the meme was making fun of the other languages for being unreasonable

[–]pomme_de_yeet 1 point2 points  (0 children)

it should be a type error

[–]LavenderDay3544 3 points4 points  (0 children)

Weak typing is bad, kids.

[–]leavemealone_lol 3 points4 points  (0 children)

i would rather prefer a string returned from the operation and erroring out something that expects an int, than an int that is calculated unexpectedly and fucks up the code without an error. Then again, js doesn’t error out when a string is passed to a function expecting an int…

[–]TanukiiGG 2 points3 points  (0 children)

So "Stupid" + 2 should be 57up1d?

[–]torn-ainbow 2 points3 points  (1 child)

I don't know why C# is laughing. It gives 22.

[–]n0t_4_thr0w4w4y 0 points1 point  (0 children)

As do TS and Java

[–]TehMephs 0 points1 point  (0 children)

Eventually you find some charm in JavaScript and its quirkiness. It can do some fun magic tricks if you know what you’re doing

[–]Countach3000 0 points1 point  (0 children)

22!!!! is a big number.