isNaN() in JavaScript.
The ๐ข๐ฌ๐๐๐() function is a ๐๐ฎ๐ข๐ฅ๐ญ-๐ข๐ง ๐๐ฎ๐ง๐๐ญ๐ข๐จ๐ง in JavaScript that is used to determine whether a ๐๐๐๐๐ is ๐๐๐ (๐๐จ๐ญ-๐-๐๐ฎ๐ฆ๐๐๐ซ) or not.
๐๐ก๐ ๐ข๐ฌ๐๐๐() ๐ฆ๐๐ญ๐ก๐จ๐:
1-returns a ๐๐จ๐จ๐ฅ๐๐๐ง ๐ฏ๐๐ฅ๐ฎ๐ (true or false).
2-return ๐ญ๐ซ๐ฎ๐ if a value is NaN, otherwise ๐๐๐ฅ๐ฌ๐.
3-๐๐จ๐ง๐ฏ๐๐ซ๐ญ๐ฌ ๐ญ๐ก๐ ๐๐๐๐๐ ๐๐ ๐ ๐๐๐๐๐๐ ๐๐๐๐จ๐ซ๐ ๐ญ๐๐ฌ๐ญ๐ข๐ง๐ ๐ข๐ญ.
๐๐ฒ๐ง๐ญ๐๐ฑ:
isNaN(value)
๐๐จ๐ฐ ๐ข๐ฌ๐๐๐() ๐ฐ๐จ๐ซ๐ค๐ฌ?
Get Muhammad Faraz Aliโs stories inย yourย inbox
Join Medium for free to get updates fromย thisย writer.
When the ๐ข๐ฌ๐๐๐() function is called with an ๐๐ซ๐ ๐ฎ๐ฆ๐๐ง๐ญ ๐ญ๐ก๐๐ญ ๐ข๐ฌ ๐ง๐จ๐ญ ๐ ๐ง๐ฎ๐ฆ๐๐๐ซ, ๐ข๐ญ ๐๐ข๐ซ๐ฌ๐ญ ๐ญ๐ซ๐ข๐๐ฌ ๐ญ๐จ ๐๐จ๐ง๐ฏ๐๐ซ๐ญ ๐ญ๐ก๐ ๐๐ซ๐ ๐ฎ๐ฆ๐๐ง๐ญ ๐ญ๐จ ๐ ๐ง๐ฎ๐ฆ๐๐๐ซ. If the argument can be converted to a valid number, the function returns ๐๐๐ฅ๐ฌ๐, indicating that the argument is not ๐๐๐.
E.g isNaN(๐ฏ๐๐ฅ๐ฎ๐) ->isNaN(๐๐ฎ๐ฆ๐๐๐ซ(value))
Examples:
//JavaScript Surgeon
//A-Numbers
isNaN(2); //false : 2 is a number
isNaN(2.4); //false : 2.4 is a number
isNaN(2โ1); //false : 2โ1=1 which is not NaN
//B-Falsy Values
isNaN(0); //false : 0 is a number
isNaN(-0); //false : -0 is a number
isNaN(false); //false : false->0 which is not NaN
isNaN(""); //false : the empty string is converted to 0 which is not NaN
isNaN(NaN); //true : NaN is not equal to any value, including itself
isNaN(undefined); //true : undefined cannot be converted into number, if we try it gives NaN
isNaN(null); //false : null is coerced to a number->0 which is not NaN
//Truthy Values
isNaN(true) //false : true ->1 (a number)
isNaN({}); //true : {} cannot be converted into number, if we try it gives NaN
isNaN([]); //false : [] when it is coerced to a number is becomes 0 (a number)
// Strings
isNaN(""); //false : the empty string is converted to 0 which is not NaN
isNaN(" "); //false : a string with spaces is converted to 0 which is not NaN
isNaN("37"); //false : "37" is converted to the number 37 which is not NaN
isNaN("37.37"); //false : "37.37" is converted to the number 37.37 which is not NaN
isNaN("2โ1"); //true : "2โ1" is a string
isNaN("37,5"); //true : "37,5" is a string
isNaN("123ABC"); //true : Number("123ABC") is NaN
// Dates
isNaN("14/04/2023"); //true : it is a string
isNaN(new Date()); //false : Date objects can be converted to a number (timestamp)
isNaN(new Date().toString()); //true : the string representation of a Date object cannot be parsed as a numberjComparisons:
isNaN(2); //false : 2 (a number)
isNaN("2"); //false : "2" is converted into 2 (a number)
isNaN(2โ1); //false : 2โ1=1 (a number)
isNaN("2โ1"); //true : "2โ1" is a string
isNaN(false); //false : false->0 (a number)
isNaN(true); //false : true ->1 (a number)
isNaN(""); //false : the empty string is converted to 0 which is not NaN
isNaN(" "); //false : a string with spaces is converted to 0 which is not NaN
isNaN(NaN); //true : NaN is not equal to any value, including itself
isNaN(undefined); //true : undefined cannot be converted into number, if we try it gives NaN
isNaN(null); //false : null is coerced to a number->0 which is not NaN
isNaN({}); //true : {} cannot be converted into number, if we try it gives NaN
isNaN([]); //false : [] when it is coerced to a number is becomes 0 (a number)








