NaN compares unequal (via ==, !=, ===, and !==) to any other value, including to another NaN value.
To test if a value is NaN, we must use Number.isNaN method.
let a = Math.sqrt(-500); console.log(Number.isNaN(a))
Note − isNaN() and Number.isNaN(): the former returns true if the value is currently NaN, or if it is going to be NaN after it is coerced to a number, while the latter will return true only if the value is currently NaN.
isNaN('hello world'); Number.isNaN('hello world');