Number isInteger() Method - Javascript Number

Javascript examples for Number:isInteger

Description

The Number.isInteger() method returns true if the value is of the type Number, and an integer. Otherwise it returns false.

Parameter Values

Parameter Description
value Required. The value to be tested

Return Value:

A Boolean. Returns true if the value is an integer Number, otherwise it returns false

The following code shows how to Check whether a value is an integer:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {/* w ww .  ja va 2s.  c o m*/
    var res = "";
    res = res + Number.isInteger(13) + ": 13<br>";
    res = res + Number.isInteger(-13) + ": -13<br>";
    res = res + Number.isInteger(5-2) + ": 5-2<br>";
    res = res + Number.isFinite(0) + ": 0<br>";
    res = res + Number.isInteger(0.5) + ": 0.5<br>";
    res = res + Number.isInteger('13') + ": '13'<br>";
    res = res + Number.isInteger(false) + ": false<br>";
    res = res + Number.isInteger(Infinity) + ": Infinity<br>";
    res = res + Number.isInteger(-Infinity) + ": -Infinity<br>";
    res = res + Number.isInteger(0 / 0) + ": 0 / 0<br>";

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

</body>
</html>

Related Tutorials