NaN, the not-a-number number that isn't NaN
6 months ago
- #JavaScript
- #IEEE754
- #NaN
- NaN (Not-a-Number) in JavaScript is a special numeric value representing an undefined or unrepresentable mathematical result.
- Any arithmetic operation involving NaN results in NaN, propagating the 'error state' through calculations.
- NaN is the only value in JavaScript that is not equal to itself (NaN !== NaN).
- The typeof NaN is 'number', as it behaves like a numeric error placeholder to maintain calculation integrity.
- To check for NaN, use isNaN() (coerces values) or Number.isNaN() (strict check without coercion).
- isNaN() checks if a value can be converted to a number, while Number.isNaN() checks if the value is exactly NaN.
- NaN's behavior is defined by the IEEE 754 floating-point standard, ensuring consistent error propagation in calculations.