NaN
is a property representing Not-A-Number.
NaN
const a = NaN, b = NaN;
console.log(a === b); // Prints: false
console.log(isNaN(a)) // Prints: true
const number = parseInt("asdasd");
console.log(number); // Prints: NaN
NaN
is a property of the global object. To check if the variable is not a number, isNaN()
function is used. NaN
is received because of following cases:
parseInt("something")
)Math.sqrt(-1)
)NaN
(e.g. 43 + NaN
)0 * Infinity
, or undefined + undefined
)"foo" / 3
)