Now I meet one strange JavaScript expression console.log(({}+[])[+[]])
, and I try to understand it with following test.
console.log([])
output[]
console.log(+[])
output0
So [+[]]
equals to [0]
, I guess it seems like an array. However, I can NOT figure out the whole expression ({}+[])[+[]]
means?
Based on the second expression, I think we can get 1
. and I make it through console.log(+!![])
, but when I try to make 2
by console.log(+!![]++!![])
, it failed.
Here is my idea 2 = 1 + 1
, so +!![]++!![]
means (+!![]) + (+!![])
. Can anyone help me figure out why it failed?