I found an interesting JavaScript question on the web. Does that mean +!{}[0]equal?
+!{}[0]
The answer really surprised me and turned out to be 1.
1
Now I am trying to understand why this syntax would lead to this.
That's why I tried to break it
!{} returns false
!{}
false
false[0] returns undefined
false[0]
undefined
+false[0] returns NaN
+false[0]
NaN
So, I can’t understand why this expression should return 1. Any theories?
You have the wrong operator priority ( MDN ). It:
{}[0] returns undefined
{}[0]
!undefined returns true
!undefined
true
+true returns 1
+true
, , , javascript , , , , {}. . [0], "" , emtpy. False "!". + , true - , , "+", 1.