What is Number.isFinite() in JavaScript?

The Number.isFinite method is used to check if the number passed to the function is a finite number or not.

The argument is considered a finite number if the argument is not equal to Positive Infinity and Negative Infinity and NaN.

Syntax

Number.isFinite(val)

The argument val must be a type of Number. Otherwise, false will be returned.

Return value

The Number.isFinite method returns true if the number passed is a finite number; otherwise, it returns false.

Example

console.log("0 :", Number.isFinite(0)); // true
console.log("\n10.12 :", Number.isFinite(10.12)); // true
console.log("\n-10 : ", Number.isFinite(-10)); // true
console.log("\nInfinity :", Number.isFinite(Infinity)); // false
console.log("\n-Infinity :", Number.isFinite(-Infinity)); // false
console.log("\nNaN :", Number.isFinite(NaN)); // false
console.log("\n'0' :", Number.isFinite('0')); // false, because '0' is a string not a number
console.log("\nnull : ", Number.isFinite(null)); // false, because 'null' is not a number

We use the Number.isFinite() method to check if the numbers are finite.

  • For the numbers 0, 10.12, -10, the isFinite method returns true. This is because they are all finite numbers.

  • For the numbers +Infinity, -Infinity, NaN, the isFinite method returns false. This is because they are all infinite numbers.

  • For the '0' string, the isFinite method returns false. This is because '0' is not a Number type.

  • For null, the isFinite method returns false. This is because null is not a Number type.

Free Resources