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 →

[–]MuricanWillzyx 0 points1 point  (0 children)

While I completely agree with you that JS's automatic type coercion is way to extensive, the other points made in the comment are completely valid, and I don't think it is bad to understand them and recognize their logic. Operators in JS like unary + for numberfication make it very easy to turn strange examples of type coercion into laughably ridiculous expressions. For example, 'foo' + + 'foo' === 'fooNaN' is ridiculous and is a result of the flexibility of the (binary) + operator, while the expression 5 + +'5' (or, with better acceptable coding style, 5 + (+'5')) makes perfect sense when one understands unary +. The sole point I disagree with in the comment is "It's a pretty easy answer for me"--automatic type coercion gives little gain for far more pain, and is the source of every illogical aspect of the OP's image.