Description

The JavaScript Number method isFinite() checks whether the given number is a finite number.

  • It returns true if the number is a finite number, otherwise returns false.
  • It is a static method, so it can be directly accessed using the class Number and doesn't need its instance.

The Infinite (or non-finite) numbers are Infinity, -Infinity, and NaN. All the other numbers are considered finite.

Syntax

The method isFinite() has the below syntax, where num is a number.

Number.isFinite(num)

Parameters

The method isFinite() allows the below parameters.

num

  • It is a number to be checked for being a finite number.
  • If the value is NaN or Infinity, the method returns false.

Result

Returns true if the given number is a finite number, otherwise returns false.

Example 1: Using the Method

The below example shows the basic usage of the method.

// Returns true
console.log(Number.isFinite(0));         // Prints: true
console.log(Number.isFinite(123));       // Prints: true
console.log(Number.isFinite(-123));      // Prints: true
console.log(Number.isFinite(5.5));       // Prints: true

// Returns false
console.log(Number.isFinite(Infinity));     // Prints: false
console.log(Number.isFinite(-Infinity));    // Prints: false
console.log(Number.isFinite(NaN));          // Prints: false
console.log(Number.isFinite(12/0));         // Prints: false

// Returns false for string values
console.log(Number.isFinite("123"));      // Prints: false

Output:

true
true
true
true
false
false
false
false
false

Overall

The JavaScript Number method isFinite() checks whether the given number is a finite number.

Related Links