DEV Community

mmvergara
mmvergara

Posted on

Understanding NaN Equality in JavaScript

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

Top comments (2)

Collapse
 
mainarthur profile image
Arthur Kh

NaN Meme
Quick meme explaining what is NaN :D

Collapse
 
mmvergara profile image
mmvergara

This should be on meme monday lmao.
dev.to/ben/meme-3opp