.isFinite()

ramanLamichhane8756805339's avatar
Published Oct 12, 2021Updated Oct 13, 2021
Contribute to Docs

The .isFinite() method is a part of the Number class in JavaScript.

It accepts a single argument, value, returns true if the passed argument is a finite number, and returns false if the passed argument is either positive Infinity, negative Infinity, or NaN.

Syntax

Number.isFinite(value);
  • value (required): The value to check.

Examples

To verify if a value is a finite number or not:

const x = 1 / 0;
// x = Infinity
console.log(Number.isFinite(x));
// Output: false
const y = 0 / 0;
// y = NaN
console.log(Number.isFinite(y));
// Output: false
const z = 10 / 5;
// z = 2
console.log(Number.isFinite(z));
// Output: true

The above example passes an Infinity, a NaN, and an integer value, into the Number.isFinite() method to verify if each value is finite or not. The result is then printed.

Codebyte Example

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy