Core JavaScript 1.5 Reference:Global Objects:Number:NaN
From MDC
Contents |
[edit] Summary
A value representing Not-A-Number.
| Property of Number | |
| Implemented in: | JavaScript 1.1, NES 2.0 |
| ECMA Version: | ECMA-262 |
[edit] Description
The value of Number.NaN is Not-A-Number, same as the value of global object's NaN property.
NaN is always unequal to any other number, including NaN itself; you cannot check for the not-a-number value by comparing to Number.NaN. Use the isNaN function instead.
Several JavaScript methods (such as the Number constructor, parseFloat, and parseInt) return NaN if the value specified in the parameter can not be parsed as a number.
You might use the NaN property to indicate an error condition for your function that returns a number in case of success.
JavaScript prints the value Number.NaN as NaN.
[edit] Examples
[edit] Example: Using NaN
In the following example, if month has a value greater than 12, it is assigned NaN, and a message is displayed indicating valid values.
var month = 13
if (month < 1 || month > 12) {
month = Number.NaN
alert("Month must be between 1 and 12.")
}