JavaScript isFinite()

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


// check if 100 is a finite number

// Output: true

// check if NaN is a finite number

// Output: false

isFinite() Syntax

The syntax of the isFinite() function is:


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

// 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

// Output: false

// check whether undefined is finite or not

// Output: false

Example 3: isFinite() With NaN and null

// check whether NaN is finite or not

// Output: false

// check whether null is finite or not

// 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.

Also Read:

Did you find this article helpful?