JavaScript - Why +! {} [0] == 1?

I found an interesting JavaScript question on the web. Does that mean +!{}[0]equal?

The answer really surprised me and turned out to be 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[0] returns undefined

+false[0] returns NaN

So, I can’t understand why this expression should return 1. Any theories?

+4
source share
2 answers

You have the wrong operator priority ( MDN ). It:

{}[0] returns undefined

!undefined returns true

+true returns 1

+9
source

, , , javascript , , , , {}. . [0], "" , emtpy. False "!". + , true - , , "+", 1.

0

All Articles