Thursday, 30 August 2018

JavaScript: isFinite: Check whether number is finite (or) not

Using isFinite function, you can check whether a number is finite (or) not. It treats all the finite numbers and Boolean values as finite numbers.

finite.html
<!DOCTYPE html>

<html>

<head>
    <title>Check Whether number is finite (or) not</title>
</head>

<body>
    <script>
        var a = 10;
        var b = Infinity;
        var c = -Infinity;
        var d = NaN;
        var e = "Hello";
        var f = true;
        var g = false;

        document.write("a = " + a + ", isFinite = " + isFinite(a) + "<br />");
        document.write("b = " + b + ", isFinite = " + isFinite(b) + "<br />");
        document.write("c = " + c + ", isFinite = " + isFinite(c) + "<br />");
        document.write("d = " + d + ", isFinite = " + isFinite(d) + "<br />");
        document.write("e = " + e + ", isFinite = " + isFinite(e) + "<br />");
        document.write("f = " + f + ", isFinite = " + isFinite(f) + "<br />");
        document.write("g = " + g + ", isFinite = " + isFinite(g) + "<br />");
    </script>
</body>

</html>


Open above page in browser, you can able to see below output.
a = 10, isFinite = true
b = Infinity, isFinite = false
c = -Infinity, isFinite = false
d = NaN, isFinite = false
e = Hello, isFinite = false
f = true, isFinite = true
g = false, isFinite = true


Previous                                                 Next                                                 Home

No comments:

Post a Comment