Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect NaN without using isNaN?

Tags:

javascript

nan

Can I write a isNan() function with JavaScript? Can JavaScript check for sure that a variable is NaN without native isNaN function?

This is a interview question.

like image 947
Mohsen Avatar asked Dec 16 '22 15:12

Mohsen


1 Answers

If it is a number, and is not equal to itself, it is NaN.

Note: As @pst has pointed out, the number constraint is unnecessary. NaN appears to be the only value in JS != itself.

like image 127
Asad Saeeduddin Avatar answered Dec 18 '22 03:12

Asad Saeeduddin