javascript - Pourquoi ++[[]][+[]]]]+[+[]]] renvoie la chaîne 10

Mots clés : javascriptsyntaxjavascript

meilleur 5 Réponses javascript - Pourquoi ++[[]][+[]]]]+[+[]]] renvoie la chaîne 10

vote vote

100

++[[]][+[]] + [+[]] 
++[[]][0] + [0] 
(+[] + 1) + [0] 
1 + [0] 
"1" + "0" === "10" // Yay! 
vote vote

85

++[[]][+[]] => 1 // [+[]] = [0], ++0 = 1 [+[]] => [0] 
1+[0].toString() = 10 
vote vote

72

( ++[[]][+[]] ) + ( [+[]] ) 
( ++[[]][0] ) + [0] 
1 + [0] 
Array.prototype.toString = function() {   return "foo"; }; ++[[]][+[]]+[+[]] 
vote vote

70

++[[]][+[]]+[+[]] = "10"  var a = [[]][+[]]; var b = [+[]];  // so a == [] and b == [0]  ++a;  // then a == 1 and b is still that array [0] // when you sum the var a and an array, it will sum b as a string just like that:  1 + "0" = "10" 
vote vote

55

+!![]+''+(+[]) 
+(true) + '' + (0) 1 + '' + 0 "10" 
_=$=+[],++_+''+$ 

Questions similaires