コンテンツにスキップ

noGlobalIsFinite

このコンテンツはまだ日本語訳がありません。

Diagnostic Category: lint/suspicious/noGlobalIsFinite

Since: v1.0.0

Use Number.isFinite instead of global isFinite.

Number.isFinite() and isFinite() do not have the same behavior. When the argument to isFinite() is not a number, the value is first coerced to a number. Number.isFinite() does not perform this coercion. Therefore, it is a more reliable way to test whether a number is finite.

isFinite(false); // true
code-block.js:1:1 lint/suspicious/noGlobalIsFinite  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

isFinite is unsafe. It attempts a type coercion. Use Number.isFinite instead.

> 1 │ isFinite(false); // true
^^^^^^^^
2 │

See the MDN documentation for more details.

Unsafe fix: Use Number.isFinite instead.

1 - isFinite(false);·//·true
1+ Number.isFinite(false);·//·true
2 2

Number.isFinite(false); // false