+ 4

How to use the isNaN function in javaScript.

Take a look at this code. var theNumber = prompt ("Pick a number", ""); if (! isNaN (theNumber)) { alert ("Your number is the square root of " + theNumber * theNumber ); How does "isNaN" and "! isNaN" work?

25th Jun 2017, 11:41 AM
Joachim Roma
Joachim Roma - avatar
1 Réponse
+ 1
isNaN() checks whether the given value/variable is a legal number or not i.e. is a number or not . It converts the provided value to number first then checks whether it's a number or not and returns true if the value is not a number else returns false.
25th Jun 2017, 2:00 PM
Sujan Poudel
Sujan Poudel - avatar