DEV Community

Discussion on: Confusing JS Explained

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 :)