Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript isNaN() Function

JavaScript isNaN() Function

Function Reference JavaScript Global Functions


Definition and Usage

The isNaN() function is used to check whether its argument is a non-numeric value.

If the argument value is NaN, or a string, object, undefined, or other non-numeric value, it returns true; otherwise it returns false.

Syntax

isNaN(value)

Parameters Description
value Required. The value to be tested.

Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the isNaN() function.


Example

Example

Check whether a number is invalid:

document

.

write

(

isNaN

(

123

)

"


"

)

;

document

.

write

(

isNaN

(

1.23

)

"


"

)

;

document

.

write

(

isNaN

(

5

2

)

"


"

)

;

document

.

write

(

isNaN

(

0

)

"


"

)

;

document

.

write

(

isNaN

(

"

Hello

"

)

"


"

)

;

document

.

write

(

isNaN

(

"

2005/12/12

"

)

"


"

)

;

The output of the above example is:

false

false

false

false

true

true

Try it »


Function Reference JavaScript Global Functions