Friday, 24 August 2018

JavaScript: Working with boolean values

Following values are considered as false.
a.   undefined
b.   Null
c.   +0, −0, or NaN
d.   Empty string

All other values, which are not mentioned above, are considered as true.

bool.html
<!DOCTYPE html>

<html>

<head>
    <title>true and false</title>
</head>

<body>
    <script type="text/javascript">
        var x = "";
        var y = "h";
        var z = 0;

        if (x) {
            document.write("x is true" + "<br />");
        } else {
            document.write("x is false" + "<br />");
        }

        if (y) {
            document.write("y is true" + "<br />");
        } else {
            document.write("y is false" + "<br />");
        }

        if (z) {
            document.write("z is true" + "<br />");
        } else {
            document.write("z is false" + "<br />");
        }
    </script>
</body>

</html>


Previous                                                 Next                                                 Home

No comments:

Post a Comment