1

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

Why is it behaving so?

0xc0de
  • 8,028
  • 5
  • 49
  • 75

1 Answers1

4

NaN is not equal to anything, not even NaN.

Reference at MDN

More detailed SO question and answer

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.
        [...]
Community
  • 1
  • 1
Ray Toal
  • 86,166
  • 18
  • 182
  • 232