created by Brian LeRoux & Andrew Lunny. sparodically uncurated by David Trejo.

2010 07 12 fail

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 [] to false. But through a number of internal function calls( binary + Operator -> ToPrimitive -> [[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 [0]. So "false"[0] returns "f".

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.

Fork me on GitHub