NaN是否等于NaN? [英] Is NaN equal to NaN?
本文介绍了NaN是否等于NaN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
parseFloat("NaN")
返回NaN ,但是
returns "NaN", but
parseFloat("NaN") == "NaN"
返回false。现在,这可能是一件好事,它确实会返回false,但我不明白这是怎么回事。 JavaScript创作者是否只是将其作为特例?
returns false. Now, that's probably a good thing that it does return false, but I don't understand how this is so. Did the JavaScript creators just make this a special case? Because otherwise I can't understand how this returns false.
推荐答案
当JavaScript函数返回 NaN
,这不是一个文字字符串,而是全局空间中的对象属性。您无法将它与字符串NaN
进行比较。
When a JavaScript function returns NaN
, this is not a literal string but an object property in the global space. You cannot compare it to the string "NaN"
.
请参阅 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/NaN
这篇关于NaN是否等于NaN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文