Inspired by this video, I tested further with {}+[]
.
Test 1:
typeof {}+[] //"object"
Okay, so {}+[]
is an object
.
Test 2:
var crazy = {}+[];
typeof crazy //"string"
What? Didn't {}+[]
is an object
? Why is it a string
now?
Test 3:
console.log({}+[])
What I got:
So it is a number
!... No?
So what actually is the type of {}+[]
??
UPDATED
To people who say {}+[]
is a empty string:
{}+[] === "" //false
({}+[]) === "" //false
({};+[]) === "" //SyntaxError
({}+[]).length //15
JavaScript is so hard to understand...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…