0xc0de
0xc0de

Reputation: 8287

Javascript variable / 'NaN' behaving weirdly

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?

Upvotes: 1

Views: 232

Answers (1)

Ray Toal
Ray Toal

Reputation: 88378

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.
        [...]

Upvotes: 4

Related Questions