JavaScript Number method: isFinite()
[this page | pdf | back links]
The isFinite() method (of the JavaScript
Number
object) returns true if value is
a finite number, otherwise returns false.
It
has the following syntax with the following parameters:
Number.isFinite(x)
Parameter
|
Required / Optional
|
Description
|
x
|
Required
|
Input parameter
|
The Number.isFinite method is subtly
different to the global isFinite
function. The latter coerces a value to a number before testing it, whilst the
former does not. So, Number.isFinite("4.3")
returns false,
whilst isFinite("4.3")
returns true.
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.isFinite(Number.MAX_VALUE * 2);';
document.getElementById("Result").innerHTML =
Number.isFinite(Number.MAX_VALUE * 2);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodNumberIsFinite() {
var z = 12.5; return !!z.isFinite;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Numbers and Math