What is use of is nan function | Sololearn: Learn to code for FREE!
0

What is use of is nan function

Javascript

6th Nov 2017, 1:46 PM
Ronak Patel
Ronak Patel - avatar
4 ответов
+ 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
6th Nov 2017, 1:59 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 2
NaN is not a function, it stands for Not a Number.
6th Nov 2017, 2:42 PM
Harsh
Harsh - avatar
+ 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
6th Nov 2017, 3:38 PM
Kirk Schafer
Kirk Schafer - avatar
+ 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.
6th Nov 2017, 9:17 PM
Rose Sevenyears
Rose  Sevenyears - avatar