Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Functions:isNaN

From MDC


Contents

[edit] Summary

Core Function

Evaluates an argument to determine if it is not a number.

[edit] Syntax

isNaN(testValue)

[edit] Parameters

testValue 
The value you want to evaluate.

[edit] Description

isNaN is a top-level function and is not associated with any object.

isNaN attempts to convert the passed parameter to a number. If the parameter can't be converted, it returns true; otherwise, it returns false.

This function is useful because the value NaN cannot be meaningfully tested with the equality operators. x == NaN and x === NaN are always false, regardless of what x is, even if x is NaN. For example, both 1 == NaN and NaN == NaN return false.

[edit] Examples

isNaN(NaN) //returns true
isNaN("string") //returns true
isNaN("12") //returns false
isNaN(12) //returns false

[edit] See also

Number.NaN, parseFloat, parseInt