Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does isNaN() do in javaScript? [duplicate]

isNaN() returns false if and only if the argument is number.

var a = new Number(1);

By doing so, a is an object now. So why is isNaN(a) returning false?

like image 669
Rohit Goyal Avatar asked Jul 24 '26 21:07

Rohit Goyal


1 Answers

isNaN() tests whether an input is NOT a number.

var a = new Number(1)

a is a number object. Therefore isNaN() returns false.

Here is a nice documentation containing isNaN() behaviors with different edge cases. Unfortunately some of them are not as intuitive as hoped, so it's worth reading.

like image 130
Ling Zhong Avatar answered Jul 27 '26 10:07

Ling Zhong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!