0

If you run alert(++[[]][+[]]+[+[]]); code in js then it will alert 10.Why is that? What logic does this code use?

sakoaskoaso
  • 347
  • 4
  • 17

1 Answers1

3

Check out jsfuck.com. This gives examples and shows how to, quite literally, write any code using it.

The basics:

false       =>  ![]
true        =>  !![]
undefined   =>  [][[]]
NaN         =>  +[![]]
0           =>  +[]
1           =>  +!+[]
2           =>  !+[]+!+[]
10          =>  [+!+[]]+[+[]]
Array       =>  []
Number      =>  +[]
String      =>  []+[]
Boolean     =>  ![]
Function    =>  []["filter"]
eval        =>  []["filter"]["constructor"]( CODE )()
window      =>  []["filter"]["constructor"]("return this")()
jhpratt
  • 6,841
  • 16
  • 40
  • 50
  • 3
    [The license](https://github.com/aemkei/jsfuck/blob/master/LICENSE.txt) _is_ pretty permissive, so that should be no problem. – LarsW Jul 28 '17 at 21:59