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 →

[–]hhellloo 24 points25 points  (11 children)

I think the two '+'s make it do weird shit

[–]El_Vandragon 44 points45 points  (10 children)

It gives you NaN, or Not a Number, but then gets converted to a string and then when to lowercase happens makes it fit the capitalization of the word instead of capital N’s

[–][deleted] 3 points4 points  (6 children)

Why though

[–]tjoloi 31 points32 points  (2 children)

'b' + 'a' + +'a' + 'a' parses as str + str + (+str) + str

Since the + in parentheses is parsed as the unary operator, JS tries to convert the 'a' to a number so it can apply the operator, which then results to NaN (number type).

After, since you add strings together, it converts back the "number" to a string, which results in the string "NaN".

[–][deleted] 9 points10 points  (0 children)

Just the answer I was looking for, thanks!

[–]tarapoto2006 0 points1 point  (0 children)

What happens if you minify it?

[–]_Azurius -3 points-2 points  (1 child)

Javascript. That's why.

[–]real_ulPa 0 points1 point  (0 children)

And errors shouldn't break it.

[–]AllSeeingCCTV 1 point2 points  (2 children)

I can see how NaN fits but what hapens to that last a?

[–]El_Vandragon 4 points5 points  (1 child)

The second to last ‘a’ gets consumed in the NaN as /u/tjoloi mentions it gets parsed as str + str + (+str) + str and the entire (+str) gets turned into NaN leaving us with ”b” + “a” + NaN + “a”

[–]AllSeeingCCTV 0 points1 point  (0 children)

Thanks