Javascript - Number isFinite() Method

The Number.isFinite() method returns whether a value is a finite number.

Description

The Number.isFinite() method returns whether a value is a finite number.

This method returns true if the value is of the type Number, and evaluated to a finite number. Otherwise it returns false.

The global isFinite() function converts the tested value to a Number, then tests it.

Number.isFinite() does not convert the values to a Number and returns false for non-number value.

Syntax

Number.isFinite(value)

Parameter Values

Parameter Require Description
value Required. The value to be tested

Return

A Boolean. Returns true if the value is a finite Number, otherwise it returns false

Example

Check whether a value is a finite number:

Demo

var res = "";
res = res + Number.isFinite(123) + ": 123\n";
res = res + Number.isFinite(-1.23) + ": -1.23\n";
res = res + Number.isFinite(5-2) + ": 5-2\n";
res = res + Number.isFinite(0) + ": 0\n";
res = res + Number.isFinite('123') + ": '123'\n";
res = res + Number.isFinite('d') + ": 'd'\n";
res = res + Number.isFinite('2015/12/12') + ": '2015/12/12'\n";
res = res + Number.isFinite(Infinity) + ": Infinity\n";
res = res + Number.isFinite(-Infinity) + ": -Infinity\n";
res = res + Number.isFinite(0 / 0) + ": 0 / 0\n";

console.log(res);/*w  w w.  ja  v a2  s  .co m*/

Result