Please enable JavaScript to use CodeHS

Chapter 2

JavaScript Control Structures

2.2 Logical Operators

What Are Logical Operators?

The NOT Operator

Light Switch

The AND Operator

The OR Operator

Wasting Time

Check Your Understanding

  1. Invalid Answer

Exercise: Can You Drive?


Term Definition
Boolean A boolean is a true or false value.
Variable A symbol or container that holds a value.
Logical operator Used to make logical associations between boolean values
Or operator Logical operator that ORs two boolean values. Written as `||`. `a || b` will be true if `a` or `b` is true.
And operator Logical operator that ANDs two boolean values. Written as `&&`. `a && b` will be true if both `a` and `b` are true.
Not operator Logical operator that negates a single boolean value. Written as `!`. `!a` will be true if `a` is false, and false if `a` is true.
Negate To flip a boolean value, or take the opposite of a boolean value. If you negate true, you get false. If you negate false, you get true.

Do you have feedback on this lesson? Let us know here
Rate this lesson:

Feedback on this lesson:

Issue found (optional):