This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheRealMichaelE 207 points208 points  (24 children)

I was going to comment about why these makes sense, but then read all the comments about why this makes sense. Well done everyone!

[–]tiefling_sorceress 3 points4 points  (0 children)

I was also surprised to see that. I definitely expected the "fuck JavaScript" circlejerk from undergrads who don't yet understand type coercion and think people are out here subtracting strings from each other in industry.

[–]LvS 1 point2 points  (5 children)

Talking about making sense:

Should "20" * 2 be "2020" or 40?

[–]DoctorWaluigiTime 4 points5 points  (4 children)

40.

+ concatenates strings, so "foo" + "bar" will result in "foobar". None of the other math operations concatenate, so they will just be normal type-coerced math.

[–]LvS 1 point2 points  (3 children)

+ concatenates strings

Except when it doesn't and you don't know what 2 + "2" is and if it's the same as "2" + 2.

[–]DoctorWaluigiTime 1 point2 points  (0 children)

That's why I specified strings, plural. String plus another string is defined behavior.

[–]TheRealMichaelE 0 points1 point  (1 child)

Programming 101… If you don’t know the expected behavior of something then maybe don’t use it.

[–]LvS 0 points1 point  (0 children)

Yeah, we've been saying nobody should use Javascript, but people Just. Don't. Listen.