NaN (Constant/static)

A literal constant whose type is a built-in primitive value.

Availability:

ECMAScript edition - 2
JavaScript - 1.3
JScript - 2.0
Internet Explorer - 4.0
Netscape - 4.06
Netscape Enterprise Server version - 2.0
Property/method value type:Number primitive
JavaScript syntax:-NaN

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.

Warnings:

See also:Arithmetic constant, Exception, Global object, Global special variable, IEEE 754, Infinity, isNaN(), Not a Number, null, Number, Number.NaN, Range error, Special number values, Value property

Property attributes:

DontEnum.

Cross-references:

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