What is the Number.isFinite() method in TypeScript?

In TypeScript, the Number.isFinite() method of the Number class is used to check if a certain number is finiteA finite number is a number that is measurable or countable .

Note: TypeScript is the superset of JavaScript. Therefore, this method also exists in JavaScript.

Syntax

Number.isFinite(number)
The syntax for isFinite() in TypeScript

Parameters

number: This is the number we want to check for finite values.

Return value

It returns true if the value is finite. Otherwise, it returns false.

Example

// create some numbers in TypeScript
let num1:number = 3224
let num2:number = 0/0
let num3:number = Number.POSITIVE_INFINITY
let num4:number = Number.NaN
let num5:number = 100
// check if they are finite
console.log(Number.isFinite(num1)) // true
console.log(Number.isFinite(num2)) // false
console.log(Number.isFinite(num3)) // false
console.log(Number.isFinite(num4)) // false
console.log(Number.isFinite(num5)) // true

Explanation

  • Lines 2–6: We use the number datatype to create and initialize a few variables.

  • Lines 4: The Number.POSITIVE_INFINITY property represents the positive infinity value. Its value is higher than any other number. It is a property of theNumber object.

  • Line 5: The Number.NaN property represents "Not-A-Number", meaning NaN is not a legal number. It returns true if the value's type is Number and NaN.

  • Lines 9–13: We use the Number.isFinite() method to check if the numbers are finite. We print the results to the console.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved