How to test variable for NaN value in JavaScript?

Anonym Peseqyf02/10/2015 08:55 PM Report
variable==NaN does not work, it returns false.

Answers

Add a answer ▾

Discussion

Anonym Gofepoc02/17/2015 11:17 AM Report
You cannot use equality test because NaN==NaN is false. Use isNaN() function:

isNaN(NaN) -> true
isNaN(1) -> false
Anonym Qazufes02/17/2015 04:43 PM Report
Or you can utilize the fact that NaN is not equal to NaN and use this expresion:

varaiable != variable

This expression is True for NaN value and False for all other values.
Add a question comment ▾