Understanding NaN Equality in JavaScript

mmvergara - Sep 6 '23 - - Dev Community

Did you know NaN == Nan is actually false?

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
Enter fullscreen mode Exit fullscreen mode

these are built-in JavaScript function that checks if a value is NaN

I learned a lot from this video

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player