For those unfamiliar with the magic behind this, the rough outline goes like this:
++ is an operator to increment a number.
The string 'a' can’t be incremented, because it’s not a number. ++'a' thus evaluates to NaN (Not a Number), which in turn is converted to the string 'NaN'.
The string concatenation expression is thus equivalent to 'b' + 'a' + 'NaN' + 'a' which evaluates to 'baNaNa' and is then lowercased to 'banana'.
(You could get more pedantic about the exact evaluation mechanisms and order, but if you’re proficient enough to make sense of that, you probably didn’t need the explanation in the first place)
That’s only the tip of the iceberg.
For those unfamiliar with the magic behind this, the rough outline goes like this:
++
is an operator to increment a number.The string
'a'
can’t be incremented, because it’s not a number.++'a'
thus evaluates toNaN
(Not a Number), which in turn is converted to the string'NaN'
.The string concatenation expression is thus equivalent to
'b' + 'a' + 'NaN' + 'a'
which evaluates to'baNaNa'
and is then lowercased to'banana'
.(You could get more pedantic about the exact evaluation mechanisms and order, but if you’re proficient enough to make sense of that, you probably didn’t need the explanation in the first place)
Based on this you can Take Shit even further with jsfuck
“Actually, this one isn’t ‘Wat’, it’s part of what makes Ruby awesome and powerful, unless of course you actually do this, at which point it’s ‘Wat’”