Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Global Functions and Values

The isFinite() function

Reference for the global isFinite() function: how it converts its argument to a number, what counts as finite, and when Number.isFinite() is the better test.

isFinite() converts its argument to a number and returns true if the result is an ordinary number: not NaN, not Infinity and not -Infinity. It is a quick guard after a division or a parse.

Because it converts first, strings that look like numbers pass the test. The stricter Number.isFinite() accepts only values that already are numbers.

JavaScript
isFinite(10 / 4);   // true
isFinite(10 / 0);   // false

Try it

JS What counts as finite

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

No output.

JS Guarding a calculation

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

No output.

Syntax

JavaScript
isFinite(value)
Name Description
value Any value. It is converted with the same rules as Number(value).

Return value: false if the converted number is NaN, Infinity or -Infinity; otherwise true.

Exceptions: a TypeError for a Symbol or a BigInt, which cannot be converted to a number implicitly.

Usage notes

  • Division by zero gives Infinity, not an error, for ordinary numbers. 0 / 0 gives NaN. Both fail isFinite().
  • Conversion makes it lenient. isFinite("25") and isFinite(null) are true (the second because null becomes 0). Use Number.isFinite() when the value must already be a number.
  • Blank strings become 0, so isFinite("") is true. Check for an empty string separately when validating input.
  • Overflow: results beyond about 1.8e308 become Infinity, which fails the test: isFinite(Number.MAX_VALUE * 2) is false.
  • Not a type check. A finite number may still be fractional; use Number.isInteger() when you need a whole number.
  • BigInt values are never Infinity, but isFinite(10n) throws; use Number.isFinite(10n), which simply returns false, or convert deliberately.

Browser support

isFinite() works in all browsers and runtimes, as does Number.isFinite() in current ones.