2014-10-12 117 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"?