console.log(++[[]][+[]]+[+[]]);
Why in the world does this print out 10 and not something else...? Its been driving me crazy for too long. I found this while reading the following article:
http://tutorialzine.com/2013/12/the-10-weirdest-programming-languages/
Perhaps someone can provide a definitive solution. I look forward to your swift responses everyone.
Answer
You can use only six different characters to write and execute any JS code. For example here are some representations to JS constructs
false => ![]
true => !![]
undefined => [][[]]
NaN => +[![]]
0 => +[]
1 => +!+[]
2 => !+[]+!+[]
10 => [+!+[]]+[+[]]
Array => []
Number => +[]
String => []+[]
Boolean => ![]
Function => []["filter"]
eval => []["filter"]["constructor"]( CODE )()
window => []["filter"]["constructor"]("return this")()
Proof at JS F*ck and detail at Why does ++[[]][+[]]+[+[]] return the string "10"?
No comments:
Post a Comment