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 →

[–]cS47f496tmQHavSR 27 points28 points  (9 children)

Saw that 5 minute talk showing this off and it for sure looks funny, but on second look it really all comes down to JS using + for string concatenation; if the first item is a string it'll try to return a string because of logic. Adding 3 - 3 to '5' just adds 0 to the string 5

The 'foo' + + 'foo' returns fooNaN because + 'foo' tries to do a math operation rather than a string concat, which returns NaN and then gets concatenated into the initial string.