I'm not sure what is happening in this line of javascript:
alert( (''+[][[]])[!+[]+!+[]] ); // shows "d"
What I've figured out:
var a = ! + []; // == true
var b = ! + [] + ! + []; // == 2
It seems that the second part is a reference into an array of letters or some sort, but I don't understand how that is coming from
(''+[][[]])
Also:
alert( (''+[][])[2] ); // nothing happens; console says "unexpected token ]"
alert( (''+[[]][])[2] ); // nothing happens; console says "unexpected token ]"
alert( (''+[[]][[]])[2] ); // shows "d"
alert( (""+true)[2] ); // shows "u"
I'll decompose it for you:
('' + [][[]])[!+[]+!+[]]
= ('' + undefined)[!+[]+!+[]] // [][[]] grabs the []th index of an empty array.
= 'undefined'[! + [] + ! + []]
= 'undefined'[(! + []) + (! + [])]
= 'undefined'[true + true]
= 'undefined'[2]
= 'd'
! + [] == true
is explained here What's the significant use of unary plus and minus operators?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With