2012-04-10 66 views
1

我有幾個文本框,其中返回javascript Number值,如果有效的數據是在文本框中,否則NaN。我得到這種奇怪的行爲。當我在firebug檢查(這兩個文本框爲空白):Javascript variable /'NaN'behaviourirdirdly

>>> hours 
NaN 
>>> minutes 
NaN 
>>> minutes == NaN 
false 
>>> hours == NaN 
false 
>>> hours == minutes 
false 

爲什麼表現如此?

回答

3

NaN不等於任何東西,甚至不是NaN

Reference at MDN

​​

對於權威人士透露,看到ECMAScript 5 Official Specification,部分11.9.111.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. 
     [...] 
+0

謝謝'isNaN'就做好了:) – 0xc0de 2012-04-10 08:23:28

相關問題