TLDR Dev · ARTICLES & TUTORIALS

WHY NAN !== NAN IN JAVASCRIPT (AND THE IEEE 754 STORY BEHIND IT)

pzarycki.com10 min read

Summary from the TLDR Dev newsletter

NaN (Not a Number) in JavaScript is part of the IEEE 754 standard for floating-point arithmetic, implemented at the hardware level, and propagates through calculations. The unique comparison behavior (`NaN !== NaN`) is an intentional design to enable the detection of invalid mathematical operations. Before the standard, undefined operations often crashed programs, but NaN allows computations to continue and the error to be caught later.