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

sakoaskoaso
- 347
- 4
- 17
-
This is a near exact duplicate of an old question. Will probably be hard to find though. This style is called "JSFuck" though btw. Read up on it. – Carcigenicate Jul 28 '17 at 21:51
-
http://www.jsfuck.com/ Read the bottom. – Carcigenicate Jul 28 '17 at 21:52
-
@Carcigenicate oh thanks – sakoaskoaso Jul 28 '17 at 21:53
-
@Ivan no idea.People probably thought i'm faking – sakoaskoaso Jul 28 '17 at 21:55
-
@Ivan Probably because there's no effort shown. If you broke this down, it would be possible to reverse engineer bits of it. – Carcigenicate Jul 28 '17 at 21:55
-
Yeah, but it sounds more like a a brain-teaser to me ;) – Ivan Jul 28 '17 at 21:57
1 Answers
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