check if value is NaN js code example
Example 1: javascript check if number
//Updated dec 2020
// The first 2 Variations return a Boolean
// They just work the opposite way around
// IsInteger
if (Number.isInteger(val)) {
// It is indeed a number
}
// isNaN (is not a number)
if (isNaN(val)) {
// It is not a number
}
// Another option is typeof which return a string
if (typeof(val) === 'number') {
// Guess what, it's a bloody number!
}
Example 2: javascript check if is nan
function isNaN(x) {
return x !== x;
};
isNaN(NaN);//true
Example 3: check if value is NaN
Number.isNaN(123)
Example 4: check if var is NaN
let b=1
let n=readline()
if(isNaN(b)){
console.log("You typed 0!")
}else{
console.log("You did not type 0!")
}