First, let me point out that NaN is a very special value: By definition, it's not equal to itself. That comes from the IEEE-754 standard that JavaScript numbers draw on. The "not a number" value is never equal to itself, even when the bits are an exact match. (Which they aren't necessarily in IEEE-754, it allows for multiple different "not a number" values.) Which is why this even comes up; all other values in JavaScript are equal to themselves, NaN is just special.
...am I missing some value in JavaScript that will return true for x !== x and false for x != x?
No, you're not. The only difference between !== and != is that the latter will do type coercion if necessary to get the types of the operands to be the same. In x != x, the types of the operands are the same, and so it's exactly the same as x !== x.
This is clear from the beginning of the definition of the Abstract Equality Operation:
- ReturnIfAbrupt(x).
- ReturnIfAbrupt(y).
If Type(x) is the same as Type(y), then
Return the result of performing Strict Equality Comparison x === y.
...
The first two steps are basic plumbing. So in effect, the very first step of == is to see if the types are the same and, if so, to do === instead. != and !== are just negated versions of that.
So if Flanagan is correct that only NaN will give true for x !== x, we can be sure that it's also true that only NaN will give true for x != x.
Many JavaScript programmers default to using === and !== to avoid some pitfalls around the type coercion the loose operators do, but there's nothing to read into Flanagan's use of the strict vs. loose operator in this case.
!==checks over!=checks. As far as I'm aware there's no other value wherex != x. But there are two distinct groups of JavaScript developers: those who prefer!=and those who prefer!==, be it for speed, clarity, expressiveness, etc. - Steve KlöstersNaNisn't a unique type, it's a number. It's a unique value that is not equal to itself. - T.J. Crowder===with NaN to make the point that NaN is not equal to itself. He's not "wrong," he's doing it as a teaching exercise, demonstrating that it doesn't work. - T.J. Crowder