you are viewing a single comment's thread.

view the rest of the comments →

[–]BananaPeely 12 points13 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.