我不确定这行
javascript中发生了什么:
alert( (''+[][[]])[!+[]+!+[]] ); // shows "d"
我发现了什么:
var a = ! + []; // == true var b = ! + [] + ! + []; // == 2
似乎第二部分是对一系列字母或某种类型的引用,但我不明白它是如何产生的
(''+[][[]])
也:
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"
解决方法
我会为你分解它:
('' + [][[]])[!+[]+!+[]] = ('' + undefined)[!+[]+!+[]] // [][[]] grabs the []th index of an empty array. = 'undefined'[! + [] + ! + []] = 'undefined'[(! + []) + (! + [])] = 'undefined'[true + true] = 'undefined'[2] = 'd'
! [] == true在这里解释What’s the significant use of unary plus and minus operators?