0
What is use of is nan function
Javascript
4 Respuestas
+ 4
Ok my mistake *ahem*
isNaN as its name It check the number is NaN or na
isNaN(-1);//false
isNaN(NaN);//true
isNaN(sqrt(-1));//true bc sqrt(-1) is NaN you know!
//More case
isNaN("");//false
isNaN("a");//true
isNaN("1");//false
And....this is some test case+polyfill
https://code.sololearn.com/WSonqWKuETZe/?ref=app
+ 2
NaN is not a function, it stands for Not a Number.
+ 1
(aside) Here's a chart showing some NaN tests; it shows usage and you don't have to worry about this much more than getting the basic idea.
Its purpose was to show an easy accident that happens when testing.numeric types, showing that isNaN() and Number.isNaN() may give different answers in the "whoops" case.
https://code.sololearn.com/WhXdhJ4RkZGY/?ref=app
+ 1
As I remember NaN isn't equial to itself,so you can simply check if x!=x. If its not equial -its NaN.
You can also be more smart about JS and its bugs or funny unusual things and check with ES6 feature ObjectIs( ) which haven't bugs like this.