JavaScript Global method: isFinite()
[this page | pdf | back links]
The JavaScript
Global
isFinite() method indicates
whether a number is a finite legal number. It returns true if the value is a finite number, otherwise returns false.
It
has the following syntax with the following parameters:
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>
<tr>
<td><code id="Example2"></code></td>
<td><code id="Result2"></code></td>
</tr>
</table>
<script>
document.getElementById("Example").innerHTML =
'var x = isFinite(Number.MAX_VALUE * 2);';
document.getElementById("Result").innerHTML =
isFinite(Number.MAX_VALUE * 2);
document.getElementById("Example2").innerHTML =
'var x = isFinite(Number.MAX_VALUE);';
document.getElementById("Result2").innerHTML =
isFinite(Number.MAX_VALUE);
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)