为什么NaN === NaN是假的? [英] Why is NaN === NaN false?
本文介绍了为什么NaN === NaN是假的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 NaN === NaN
在Javascript中返回 false
?
Why does NaN === NaN
return false
in Javascript?
> undefined === undefined
true
> NaN === NaN
false
> a = NaN
NaN
> a === a
false
在文档页面我看到了:
针对NaN的测试
平等运营商(
==
和== =
)不能用于测试NaN
的值。请改用isNaN
。
Testing against NaN
Equality operator (
==
and===
) cannot be used to test a value againstNaN
. UseisNaN
instead.
是否有任何参考可以回答问题?这将是受欢迎的。
Is there any reference that answers to the question? It would be welcome.
推荐答案
严格答案:因为JS规范这样说:
- 如果Type(x)是Number,那么
- 如果x是NaN,则返回false。
- 如果y是NaN,则返回false。
有用的答案:浮点数的IEEE 754规范(所有语言都用于浮点数)表明NaN永远不会等于。
Useful answer: The IEEE 754 spec for floating-point numbers (which is used by all languages for floating-point) says that NaNs are never equal.
这篇关于为什么NaN === NaN是假的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文