What is the isFinite() method in JavaScript?

The isFinite method is used to check if the value passed to the function is a finite number or not. The isFinite method is available in the window object.

A value is considered a finite value, if the value is not equal to Positive Infinity, Negative Infinity, NaN, and undefined.

Syntax

isFinite(val)

The argument val will be be converted to Number if the passed value is not a type of Number.

Return value

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

Example

console.log("0 :", isFinite(0)); // true
console.log("\n10.12 :", isFinite(10.12)); // true
console.log("\n-10 : ", isFinite(-10)); // true
console.log("\nInfinity :", isFinite(Infinity)); // false
console.log("\n-Infinity :", isFinite(-Infinity)); // false
console.log("\nNaN :", isFinite(NaN)); // false
console.log("\nNaN :", isFinite(undefined)); // false
console.log("\n'0' :", isFinite('0'));
console.log("\nnull : ", isFinite(null));
console.log("\nnull : ", isFinite('test'));

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

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

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

  • For the '0' string, the isFinite method will first convert the '0' string to a number. If '0' is converted to a number we will get 0, which is a finite value. So, true will be returned.

  • For null, the isFinite method will first convert the null to a number. If null is converted to a number we will get 0, which is a finite value. So, true will be returned.

  • For the test string, the isFinite method will first convert the test string to a number. If test is converted to a number we will get NaN, which is an infinite value. So, false will be returned.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources