JavaScript Number method: isInteger()
[this page | pdf | back links]
The isInteger() method (of the JavaScript
Number
object) returns true if value is of type Number and is an integer (within range
understood as integers by the browser), otherwise returns false.
It
has the following syntax with the following parameters:
Number.isInteger(x)
Parameter
|
Required / Optional
|
Description
|
x
|
Required
|
Input parameter
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
document.getElementById("Example").innerHTML =
'var x = Number.isInteger(2/3);';
document.getElementById("Result").innerHTML =
Number.isInteger(2/3);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodNumberIsInteger() {
var z = 12.5; return !!z.isInteger;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Numbers and Math