JavaScript Number isFinite() method

The isFinite function in JavaScript assesses if a specified value is a finite number. It yields true when the value represents a finite number; otherwise, it produces false.

Syntax

The syntax for the isFinite method is expressed as follows:

Example

Number.isFinite(num)

Parameter

num - A number to be checked.

Return

A Boolean value.

JavaScript Number isFinite method example

In this section, we will explore the isFinite method by examining several examples.

Example 1

Let's see a simple example of isFinite method.

Example

<script>

var x=0;

var y=1;

var z=-1;

document.writeln(Number.isFinite(x));

document.writeln(Number.isFinite(y));

document.writeln(Number.isFinite(z)); 

</script>

Output:

Output

true true true

Example 2

In this illustration, we will demonstrate the use of the isFinite method with negative numerical values.

Example

<script>

function check(x,y)

{

  return x/y;

}

document.writeln(Number.isFinite(check(0,10)));

document.writeln(Number.isFinite(check(10,0))); 

</script>

Output:

Output

true false

Example 3

Let’s examine the isFinite function through various test scenarios.

Example

<script>

document.writeln(Number.isFinite(Infinity));

document.writeln(Number.isFinite(-Infinity));

document.writeln(Number.isFinite(NaN)); 

</script>

Output:

Output

false false false

Input Required

This code uses input(). Please provide values below: