2014-10-12 81 views
0
console.log(++[[]][+[]]+[+[]]); 

为什么在这个世界上这个打印出10个而不是其他的东西......?它让我疯狂了太久。我发现这个在阅读下面的文章:为什么打印出10张?

http://tutorialzine.com/2013/12/the-10-weirdest-programming-languages/

也许有人可以提供一个明确的解决方案。我期待着你的迅速回应。

+0

复制,复制..太,通过搜索网站'“++ []”'发现完全匹配(当使用引号时,stackoverflow内部搜索支持查找符号)。 – user2864740 2014-10-12 09:43:06

+0

这是一个实际的问题? – 2014-10-12 09:43:10

+0

该页面底部的Stackoverflow链接:http://stackoverflow.com/questions/7202157/why-is-10,http://stackoverflow.com/questions/4170978/explain-why-this-works?lq=1 – Winestone 2014-10-12 09:46:40

回答

3

您只能使用六个不同的字符来编写和执行任何JS代码。例如这里有一些交涉,JS在JS F*ck和细节构造

false  => ![] 
true  => !![] 
undefined => [][[]] 
NaN   => +[![]] 
0   => +[] 
1   => +!+[] 
2   => !+[]+!+[] 
10   => [+!+[]]+[+[]] 
Array  => [] 
Number  => +[] 
String  => []+[] 
Boolean  => ![] 
Function => []["filter"] 
eval  => []["filter"]["constructor"](CODE)() 
window  => []["filter"]["constructor"]("return this")() 

证明在Why does ++[[]][+[]]+[+[]] return the string "10"?