noGlobalIsNan
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/noGlobalIsNan¥Diagnostic Category:
lint/suspicious/noGlobalIsNan -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
¥How to configure
{ "linter": { "rules": { "suspicious": { "noGlobalIsNan": "error" } } }}¥Description
使用 Number.isNaN 而不是全局 isNaN。
¥Use Number.isNaN instead of global isNaN.
Number.isNaN() 和 isNaN() 没有相同的行为。当 isNaN() 的参数不是数字时,首先将值强制转换为数字。Number.isNaN() 不执行此强制。因此,这是一种更可靠的方法来测试值是否为 NaN。
¥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
¥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 │
¥Valid
Number.isNaN({}); // false¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号