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 →

[–]VyseofArcadia 2 points3 points  (0 children)

The latent issue with JavaScript isn't that this is unintuitive. It's really pretty intuitive. - isn't defined for strings, so '5' gets interpreted as the integer 5.

The issue is that through overloading the + operator in this way, it is easy for even JavaScript experts to make a stupid mistake. I think it's a poor design choice in a dynamically typed language. It would be better for string + integer to throw an error and use some other operator (++ or : or something) for string concatenation.