The Lies of "===" operator

giandodev

GiandoDev

Posted on April 30, 2020

The Lies of "===" operator

It is funny to know that there is two occasions where === returns a lying result.
The first is:

0 === -0 // True

To avoid this is useful to use Object.is()

Object.is(0, -0) // False

The second is:

NaN === NaN // false

To avoid this is useful to use isNaN()

Number.isNaN(NaN) // True

More about comparison operators MDN

💖 💪 🙅 🚩
giandodev
GiandoDev

Posted on April 30, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related