Javascript变量/'NaN'表现异常 [英] Javascript variable / 'NaN' behaving weirdly
本文介绍了Javascript变量/'NaN'表现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个文本框,如果文本框中包含有效数据,则返回javascript Number
值,否则返回NaN
.我得到这种奇怪的行为.当我签入firebug
时(两个文本框均为空白):
I have a couple of textboxes, Which return javascript Number
values if valid data is in the textboxes, otherwise NaN
. I get this strange behavior. When I checked in firebug
(both the textboxes are blank):
>>> hours
NaN
>>> minutes
NaN
>>> minutes == NaN
false
>>> hours == NaN
false
>>> hours == minutes
false
为什么会这样?
推荐答案
NaN
不等于任何东西,甚至不等于NaN
.
NaN
is not equal to anything, not even NaN
.
有关权威信息,请参见 ECMAScript 5官方规范 , 11.9.1 和 11.9.3 :
For the authoritative source, see the ECMAScript 5 Official Specification, sections 11.9.1 and 11.9.3:
1. If Type(x) is the same as Type(y), then
[...]
c. If Type(x) is Number, then
i. If x is NaN, return false.
ii. If y is NaN, return false.
[...]
这篇关于Javascript变量/'NaN'表现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文