与Java中的NaN进行比较 [英] Comparing with NaN in Javascript
本文介绍了与Java中的NaN进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了这个奇怪的问题.
I have met this strange issue.
为什么会这样?应该是这样吗?
Why is so?! Should it be so?
推荐答案
来自 isNaN
的MDN文档:
From the MDN docs for isNaN
:
与JavaScript中所有其他可能的值不同,不可能 依靠相等运算符(==和===)来确定是否 值是否为NaN,因为NaN == NaN和NaN === NaN都会求值 虚假.因此,必须要有isNaN函数.
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.
改用 isNaN
.
这篇关于与Java中的NaN进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文