Number isFinite() Method - Javascript Number

Javascript examples for Number:isFinite

Description

The Number.isFinite() method returns true if the value is of the type Number, and equates 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 will not return true for any value that is not of the type Number.

Parameter Values

Parameter Description
value Required. The value to be tested

Return Value:

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

The following code shows how to Check whether a value is a finite number:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w  ww  . j ava  2s .  c om
    var res = "";
    res = res + Number.isFinite(13) + ": 13<br>";
    res = res + Number.isFinite(-1.3) + ": -1.3<br>";
    res = res + Number.isFinite(5-2) + ": 5-2<br>";
    res = res + Number.isFinite(0) + ": 0<br>";
    res = res + Number.isFinite('123') + ": '123'<br>";
    res = res + Number.isFinite('Hello') + ": 'Hello'<br>";
    res = res + Number.isFinite('2020/12/12') + ": '2020/12/12'<br>";
    res = res + Number.isFinite(Infinity) + ": Infinity<br>";
    res = res + Number.isFinite(-Infinity) + ": -Infinity<br>";
    res = res + Number.isFinite(0 / 0) + ": 0 / 0<br>";

    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials