math/prefer-number-is-nan
enforce the use of Number.isNaN() instead of other checking ways
- ⚙️ This rule is included in
"plugin:math/recommended"
. - 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule. - 💡 Some problems reported by this rule are manually fixable by editor suggestions.
📖 Rule Details
This rule aims to enforce the use of Number.isNaN()
instead of other checking ways.
Number.isNaN()
is the most reliable way to check for NaN values because:
- Type safety: Only returns
true
for actual NaN values, not for non-numeric types - No type coercion: Unlike global
isNaN()
, it doesn't convert values to numbers first - Clear intent: Explicitly shows you're checking for the NaN value
- Performance: Direct comparison without type conversion overhead
- Consistency: Part of the modern Number API alongside other type-checking methods
🔧 Options
Nothing.
📚 Further reading
🚀 Version
This rule was introduced in eslint-plugin-math v0.4.0