JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

isNaN() Function

Name

isNaN() Function---check for Not-a-Number

Availability

Navigator 3.0; Unix platforms in Navigator 2.0; implemented but nonfunctional in Internet Explorer 3.0

Synopsis

isNaN(x)

Arguments

x

The value to be tested.

Returns

true if x is the reserved value NaN (not-a-number); false if x is a legal number, string, or any other type.

Description

isNaN() tests its argument to determine whether it is the reserved value NaN, which represents an illegal number (such as the result of division by zero). This function is required, because comparing a NaN with any value, including itself, always returns false, so it is not possible to test for NaN with the == operator.

The NaN value is not implmemented in Internet Explorer 3.0, so isNaN() always returns false on that platform.

A common use of isNaN() is to test the result of parseFloat() and parseInt() to determine if they represent legal numbers. You can also use it to check for arithmetic errors, such as division by zero.

See Also

"Number.NaN", "parseFloat()", "parseInt()"


Previous Home Next
Image.width Book Index java

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell