noGlobalIsNan
このコンテンツはまだ日本語訳がありません。
Summary
Section titled “Summary”- Rule available since:
v1.0.0 - Diagnostic Category:
lint/suspicious/noGlobalIsNan - This rule is recommended, which means is enabled by default.
- This rule has an unsafe fix.
- The default severity of this rule is warning.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noGlobalIsNan": "error" } } }}Description
Section titled “Description”Use Number.isNaN instead of global isNaN.
Number.isNaN() and isNaN() do not have the same behavior.
When the argument to isNaN() is not a number, the value is first coerced to a number.
Number.isNaN() does not perform this coercion.
Therefore, it is a more reliable way to test whether a value is NaN.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”isNaN({}); // truecode-block.js:1:1 lint/suspicious/noGlobalIsNan FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
> 1 │ isNaN({}); // true
│ ^^^^^
2 │
ℹ See the MDN documentation for more details.
ℹ Unsafe fix: Use Number.isNaN instead.
1 │ - isNaN({});·//·true
1 │ + Number.isNaN({});·//·true
2 2 │
Number.isNaN({}); // falseRelated links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.