Skip to content

noGlobalIsFinite (since v1.0.0)

Diagnostic Category: lint/suspicious/noGlobalIsFinite

Use Number.isFinite instead of global isFinite.

Number.isFinite() and isFinite() have not 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
suspicious/noGlobalIsFinite.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