JavaScript – Logical Operators

Logical operators: These operators return a boolean value by validating more than one expression. Operators are &&, ||, !

Expression1Expression2&&||!Expression1!Expression2
TTTTFF
TFFTFT
FTFTTF
FFFFTT

Code:

<html>
            <body>
                        <script>
                                    document.write(“true && true = ” + (true && true) + “<br/>”);
                                    document.write(“true && false = ” + (true && false) + “<br/>”);
                                    document.write(“true || true = ” + (true || true) + “<br/>”);
                                    document.write(“true || false = ” + (true || false) + “<br/>”);
                        </script>
            </body>
</html>

Condition to check First Num is greater than both Second & Third Nums or Not:

Variables:
var a=?, b=?, c=?;
 
Condition:
            a > b && a > c

Condition to check the number divisible by both 3 and 5 or not:

Variables:
var n=?;
 
Condition:
            n % 3 == 0 && n % 5 == 0

Condition to check the number is in between 30 and 50 or not:

Variables:
var n=?;
 
Condition:
            n >= 30 && n <= 50

Condition to check the student passed in all 4 subjects or Not:

Variables:
var m1=?, m2=?, m3=?, m4=?;
 
Condition:
            M1>=40 && m2>=40 && m3>=40 && m4>=40

Condition to check the character is Vowel or Not:

Variables:
var ch = ‘?’;
 
Condition:
            ch == ‘a’ || ch == ‘e’ || ch== ‘i’ || ch==’o’ || ch==’u’

Condition to check the character is Upper case alphabet or not:

Variables:
var ch=’?’;
 
Condition:
            ch >= ‘A’ && ch <= ‘Z’

Condition to check the character is Alphabet or not:

Variables:
var ch=’?’;
 
Condition:
            (ch >= ‘A’ && ch <= ‘Z’) || (ch >= ‘a’ && ch <= ‘z’)

Condition to check the 3 numbers equal or not:

Variables:
var a=?, b=?, c=?;
 
Condition:
            a == b && b == c

Condition to check any 2 numbers equal or not among the 3 numbers:

Variables:
var a=? , b=? , c=?;
 
Condition:
            a==b || b==c || c=a

Condition to check the 3 numbers are unique or not:

Variables:
var a=? , b=? , c=?;
 
Condition:
            a!=b && b!=c && c!=a
Scroll to Top