Code highlights logo


Conditional Statements

Logical Operators

Logical operators are used to combine multiple boolean expressions and determine the overall truth or falsehood of the combined expression. They are particularly useful for making decisions based on multiple conditions.

There are three main logical operators: AND, OR, and NOT.

  • AND Operator (&&): The AND operator returns true if both of its operand expressions are true. Otherwise, it returns false.
    1if (age >= 18 && hasValidLicense) {
    2 console.log("You can drive a car.");
  • OR Operator (||): The OR operator returns true if at least one of its operand expressions is true. If both expressions are false, it returns false.
    1if (isWeekend || isHoliday) {
    2 console.log("It's time to relax.");
  • NOT Operator (!): The NOT operator returns the opposite boolean value of its operand expression. If the expression is true, it returns false. If the expression is false, it returns true.
    1if (!isRaining) {
    2 console.log("It's a sunny day!");

You can also combine multiple logical operators to create more complex conditions.

Remember to use parentheses () when combining logical operators to control the order of evaluation.

Now that we understand logical operators, we can use them within conditional statements to make more nuanced decisions in our code.



Create a variable result1 and assign the value of x less than or equal to y using the <= operator.


Create a variable result2 and assign the value of y greater than x and z using the && operator.

Sign up to start coding

Already have an account?

Sign In

Course content