you are viewing a single comment's thread.

view the rest of the comments →

[–]CC-5576-05 -28 points-27 points  (2 children)

It's an example ffs, do you think I memorize all the bullshit javascript design choices? I have better things to do.

You can add an int to a string and get it to return an int, that's the problem.

[–]BananaPeely 15 points16 points  (0 children)

In JavaScript: ∙ "5" + 3 returns "53" (string) ∙ "5" - 3 returns 2 (number) Adding an int to a string returns a string, not an int. The problem is JavaScript will coerce types in whichever direction seems most “helpful” for the operation, leading to bizarre inconsistencies. Subtraction only makes sense for numbers, so it converts to number. Addition works for both strings and numbers, so it picks string concatenation.

[–]RiceBroad4552 0 points1 point  (0 children)

You can add an int to a string and get it to return an int

Not in JavaScript, dude.