Did you know
NaN == Nan
is actuallyfalse
?
This might seem counterintuitive, but it's because NaN represents an indeterminate
or undefined
value. Therefore, it's impossible to equate two NaN values using the equality operator.
The correct way of checking for NaN is yung the isNan
console.log(Number.isNaN(NaN)); // True
console.log(isNaN(NaN)); // True
these are built-in JavaScript function that checks if a value is NaN