Logical operators are typically used with Boolean (logical) values like true or false, similarly 1 or 0.
We will be discussing 3 major logical operators in this chapter.
| Operator | Symbol | Syntax | Description |
|---|---|---|---|
| Logical AND | && | x && y | If x is true, then returns value of y; else, returns value of x. |
| Logical OR | || | x || y | If x is true, then returns value of x; else, returns value of y. |
| Logical NOT | ! | !x | If x is true, then returns false; otherwise, returns true. |
Examples
LOGICAL AND
| Boolean | Symbol | Boolean | Result |
|---|---|---|---|
| True | && | True | True |
| True | && | False | False |
| False | && | True | False |
| False | && | False | False |
LOGICAL OR
| Boolean | Symbol | Boolean | Result |
|---|---|---|---|
| True | || | True | True |
| True | || | False | True |
| False | || | True | True |
| False | || | False | False |
LOGICAL NOT
| Expression | Result |
|---|---|
| !True | False |
| !False | True |