The primitive value NaN represents the IEEE 754 "Not-a-Number" value. This is returned when the result of an evaluation is known to yield a numeric value but its magnitude and sign is uncertain. Because the value is numeric but uncertain, you cannot compare NaN with anything else (including itself). However you can test for its existence with the isNaN() function.
In IEEE 754, there are many millions of possible values for NaN. In ECMA compliant JavaScript interpreters, they are all collected together and referred to as a single value. This means you cannot distinguish the reason for the NaN error as you may be able to in other languages that use IEEE 754 arithmetic.
It is possible in the hosting environment to provide additional facilities to determine what sort of NaN values you have. This is implementation-dependent however and not part of the standard.
If you are in an environment that does not have the NaN value implemented, then you may be able to create one yourself like this:
var NaN = 0/0;
The value has existed since JavaScript 1.1 but it was given a property name in JavaScript 1.3. Therefore from scripting point of view, its availability is defined as JavaScript 1.3 and not 1.1.
Be careful not to assign your own values to this variable. You can corrupt it in some implementations. In MSIE version 5 for Macintosh, assigning a value to the global NaN value changes its setting but leaves Number.NaN unaffected. You cannot modify Number.NaN.
Version 3.02 of MSIE with JScript version 1.0 silently converts NaN values to zero. It does not know what NaN is.
Netscape 2.02 cannot tell the difference between null and undefined.
This constant is available as a property of the Global object in MSIE version 4 but not in Netscape 4.
ECMA 262 edition 2 - section - 4.3.23
ECMA 262 edition 2 - section - 15.1.1.1
ECMA 262 edition 3 - section - 4.3.23
ECMA 262 edition 3 - section - 15.1.1.1
Wrox Instant JavaScript - page - 14
| Prev | Home | Next |
| Namespace | Up | native |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||