How does this js code output 10?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How does this js code output 10??

alert(++[[]][+[]]+[+[]]);

29th Nov 2021, 8:00 PM
MATOVU CALEB
MATOVU CALEB - avatar
2 Answers
+ 6
I don't know how it works but is called jsfuck: https://en.m.wikipedia.org/wiki/JSFuck http://www.jsfuck.com/
29th Nov 2021, 8:11 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
[] is an empty array, if you put + in front of it, the compiler converts it to Integer: +[] => 0 ++[[]][+[]] respectively, this is the first value of the empty array to which 1 was added. As a result, '1' + '0' => 10
29th Nov 2021, 8:57 PM
Solo
Solo - avatar