There are two reasons, one practical and one historical. The historical reason is that this makes it trivial to test for a NaN. If the value isn't equal to itself, it's a NaN.
The practical reason is that NaN is used to indicate various different cases where the value is not defined, and not all undefined values are equal.
Should NaN
/NaN
equal 1? Think about how crazy that would be. Arguing that NaN
should equal itself is only a bit less crazy.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…