Prefer Number Static Methods

ID

javascript.prefer_number_static_methods

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Best Practice

Language

JavaScript

Tags

best-practice, numeric, simplification

Description

Reports a call to one of the four numeric globals that Number also carries: parseInt, parseFloat, isNaN and isFinite.

const n = parseInt(input, 10);   // FLAW
if (isNaN(value)) { }            // FLAW

Only a bare call is reported. A call through a receiver — Number.parseInt(…​), window.parseInt(…​) — is already namespaced, and a call that resolves to a function declared in the file is a local of the same name rather than the global.

Rationale

The two pairs earn the report for different reasons.

  • Number.parseInt and Number.parseFloat are specified to be the same function objects as the globals. The change is about saying where the operation comes from: a bare parseInt in a module reads like an import someone forgot to add.

  • isNaN and isFinite are the ones that matter. The globals coerce their argument to a number first, so isNaN("hello") is true and isFinite("42") is true — they answer a question about the coercion, not about the value. Number.isNaN and Number.isFinite do not coerce; they answer false for anything that is not already a number, which is what the call site nearly always meant.

Remediation

Call the Number static method.

const n = Number.parseInt(input, 10);
const x = Number.parseFloat(input);
if (Number.isNaN(value)) { }
if (Number.isFinite(value)) { }

Where the coercing behaviour of the old isNaN really was intended, make it explicit: Number.isNaN(Number(value)).

© 2026 Xygeni. All rights reserved