DEV Community

Discussion on: Confusing JS Explained

Collapse
tqbit profile image
tq-bit

Came for the meme, stayed for the code.
Stuff like this is the reason why I love javascript.
Had my first wtf moment when trying:

('b' + 'a' + + 'a' + 'a').toLowerCase()

Collapse
devendra0110 profile image
Devendra Gaud

Can you explain it?

Collapse
sanfra1407 profile image
Giuseppe

When your run 'a' + + 'a' you're doing 'a' + +'a'. JavaScript tries to cast +'a' to a number which is cleary impossible; so it returns NaN (Not a Number) and then it concatenates the NaN to other chars, creating the baNaNa string. The magic happens with the toLowerCase() method :)