Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Number and BigInt

Number.isFinite()

Reference for Number.isFinite(): checking that a value is a real, finite number without type coercion, and how it differs from the global isFinite().

Number.isFinite() returns true only when the argument is of type number and is neither NaN, Infinity nor -Infinity. It never converts its argument, so any non-number gives false.

The older global isFinite() first converts its argument with Number(), which makes isFinite("12") and isFinite(null) return true. The method on Number is the stricter and safer choice.

JavaScript
Number.isFinite(value)

Try it

JS Number.isFinite() versus isFinite()

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Detecting overflow in a calculation

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
Number.isFinite(value)
Name Description
value The value to test. Any type is accepted.

Return value: true if value is a number that is not NaN and not infinite; otherwise false.

Exceptions: none. (The global isFinite() throws a TypeError for BigInt and Symbol values because it converts them first.)

Usage notes

  • No coercion: Number.isFinite("5") is false. Convert first if you want to accept numeric strings, for example Number.isFinite(Number(input)).
  • Global version quirks: isFinite(""), isFinite(null) and isFinite(true) are all true because they convert to 0 or 1.
  • What fails the test: NaN, Infinity and -Infinity, plus every non-number type.
  • Typical uses: validating the result of a division or Math function, rejecting bad values before drawing a chart or setting a CSS number, and filtering datasets.
  • Division by zero gives Infinity or NaN, not an exception.
  • Overflow: results beyond Number.MAX_VALUE become Infinity, so a finite check catches them.
  • Integers: a finite number need not be an integer; for that use Number.isInteger().
  • JSON: JSON.stringify() turns NaN and Infinity into null, so check before serializing.

Browser support

Supported in all current browsers; it arrived with ES2015.