JavaScript isFinite()

The isFinite() function checks whether the passed value is a finite number.

Example

// check if 100 is a finite number
console.log(isFinite(100));

// Output: true

// check if NaN is a finite number
console.log(isFinite(NaN));

// Output: false

isFinite() Syntax

The syntax of the isFinite() function is:

isFinite(testValue)

isFinite() Parameters

The isFinite() function takes in:

  • testValue - value to be tested for finiteness.

isFinite() Return Value

The isFinite() function returns

  • false - if the argument is Infinity or NaN or undefined
  • true - for all other arguments

Example 1: JavaScript isFinite()

// check whether 5463 is finite or not
console.log(isFinite(5463));

// Output: true

In the above example, we have used isFinite() to check whether the given value is finite or not. The output is true, as 5463 is a finite number.


Example 2: isFinite() With Infinity and undefined

// check whether Infinity is finite or not
console.log(isFinite(Infinity));

// Output: false

// check whether undefined is finite or not
console.log(isFinite(undefined));

// Output: false

Example 3: isFinite() With NaN and null

// check whether NaN is finite or not
console.log(isFinite(undefined));

// Output: false

// check whether null is finite or not
console.log(isFinite(null));

// Output: true

Note: In JavaScript, isFinite() is a top-level function because it is not associated with any object or class, and we can call it from anywhere without creating an instance.


Recommended Reading:

Did you find this article helpful?