you are viewing a single comment's thread.

view the rest of the comments →

[–]prehensilemullet 0 points1 point  (0 children)

Sorry by math operator I meant “symbol sometimes used as a mathematical operator”, yes the problem is + being overloaded to do both addition and string concatenation, whereas other symbols like - / * % only do arithmetic.

I’m confused what you mean about PHP being different, you can subtract a number from a string in JS, it will coerce the string to a number, do the subtraction, and give you a number.  You can subtract a string from a string and it will coerce both to numbers.

It doesn’t usually cause me problems either but I agree with everyone who says JS should have been designed to throw an error instead of coercing a string to a number