MDN "Object.is" alternative proposal
It kinda is written in the same article:
This is also not the same as being equal according to the === operator. The === operator (and the == operator as well) treats the number values -0 and +0 as equal, and it treats Number.NaN as not equal to NaN.
The logic is that NaN !== NaN
is the only case in which the !==
operator returns true
on the same variable, so it must be about NaN
comparison. It then does the same check on v2
and returns true of false based on the outcome: if v2
comparison is true
, it's about NaN compared to NaN so return true
, if not then return false
because NaN is never the same as something that isn't NaN.