Logical

Logical Operators

Logical operators combine or invert boolean conditions. They are used to build compound conditions — checks that require more than one thing to be true at the same time, or where either of two things being true is enough.

For a broader introduction to operators, see Operators.

AND#

The AND operator returns true only when both conditions are true. If either is false, the result is false.

Left Right Result
true true true
true false false
false true false
false false false
int score = 7;
bool result = score > 5 && score < 10;  // true
score = 7
result = score > 5 and score < 10  # True
let score = 7;
let result = score > 5 && score < 10;  // true

OR#

The OR operator returns true when at least one condition is true. It only returns false when both are false.

Operators

An operator is a symbol that performs an operation on one or more values. The values it operates on are called operands, and the result is a new value.

  operand   operator   operand
     5          +          3
              result
                8

Types of Operators#

Arithmetic Operators#

Perform mathematical calculations — addition, subtraction, multiplication, division, modulo.

See Arithmetic Operators for a full explanation and examples.

Comparison Operators#

Compare two values and produce a true or false result. Used to build conditions in if/else statements and loops.