문제

As it says in the question really, I tried value == NaN and it was false and then remembered that I should be using isNaN(value) to check for this.

Why the difference?

도움이 되었습니까?

해결책

both NaN == NaN and NaN === NaN evaluate to false as from MDN

NaN is a special value which you can think of as for example Infinity. Infinity is not equal to another Infinity as it has NO DEFINED VALUE.

다른 팁

I can't put it any better than MDN do so...

Unlike all other possible values in JavaScript, it is not possible to rely on the equality operators (== and ===) to determine whether a value is NaN or not, because both NaN == NaN and NaN === NaN evaluate to false. Hence, the necessity of an isNaN function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top