Tuesday, May 14, 2024

JavaScript Logical Operators

 Logical Operators in JavaScript
The following are the logical operators supported by JavaScript:

Operator    Name        Example
&&        Logical And    ( a< 5 && b>2)
||        Logical Or    (a<5 || b>2)
!        Not        (a!=5)

<!DOCTYPE>
<html>
<head>
    <title>JavaScript</title>
    <script>
        /* Logical And Operator */
        var age = 18;
       
        if (age >= 18 && age <= 21) {
            document.write("Yes you are eligible.");
        }
        document.write("<br><br>");

        /* Logical OR Operator */
        var a = 10;
        var b = 15;
        if (a >= 8 || b <= 15) {
            document.write("Yes you are eligible.");
        }
        document.write("<br><br>");
        
        /* Logical Not Operator */
        var x = 30;

        console.log(!x >= 12);
    </script>
</head>
<body>
</body>
</html>

No comments:

Post a Comment