Let's take the last post a step further:
console.log( (!+)[+]+(!+)[+!+]+([!]+[])[+!++[+]]+(!+)[!++!+] ) // "fail"
Breaking that mass of symbols into pieces we notices, that the following patten occurs often:
console.log( (!+) ) // "false" console.log( ! ) // false
So we try adding
false. But through a number of internal function calls(
binary + Operator ->
[[DefaultValue]]) we end up with converting the right operand to a String:
console.log( .toString() ) // "" console.log( (!+.toString()) ) // false + ""
Aha, so we are concatenating strings here! Now this is plain obvious! Moving on to the next bit:
console.log( [+] ) // [ 0] console.log( + ) // 0
Thinking of a
String as an
Array we can access its first character via
I think you got the idea now and can figure out the rest by yourself!
Thanks to Mathias Bynens for pushing this out int the web.