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; // truescore = 7
result = score > 5 and score < 10 # Truelet 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.