|
1 | 1 | # Control Flows: Conditions and Iterations |
2 | 2 |
|
| 3 | +**Comparison** and **Logical** operators are used in *conditional* statements and serve to test for `ture` or `false`. |
| 4 | + |
| 5 | +## Comparison Operators |
| 6 | + |
| 7 | +The Comparison operators are used in logical statements to determine equality or difference between variables or values. |
| 8 | + |
| 9 | +Let's assume that `x = 5`. The table below explains the comparison operators: |
| 10 | + |
| 11 | +| Operator | Description | Comparing | Returns | |
| 12 | +|--------------------|-------------------------------------|-----------|----------| |
| 13 | +| == | equal to | x == 8 | false | |
| 14 | +| == | equal to | x == 5 | true | |
| 15 | +| == | equal to | x == "5" | true | |
| 16 | +| | | | | |
| 17 | +| === | equal value and equal type | x === 5 | true | |
| 18 | +| === | equal value and equal type | x === "5" | false | |
| 19 | +| | | | | |
| 20 | +| != | not equal | x != 8 | true | |
| 21 | +| | | | | |
| 22 | +| !== | not equal value or not equal type | x !== 5 | false | |
| 23 | +| !== | not equal value or not equal type | x !== "5" | true | |
| 24 | +| !== | not equal value or not equal type | x !== 8 | true | |
| 25 | +| | | | | |
| 26 | +| > | grater than | x > 8 | false | |
| 27 | +| < | less than | x < 8 | true | |
| 28 | +| >= | grater than or equal to | x >= 8 | false | |
| 29 | +| <= | less than or equal to | x <= 8 | true | |
| 30 | + |
| 31 | +## Logical Operators |
| 32 | + |
| 33 | +The logical operators are used to determine the logic between variables or values. Let's take that `x = 6` and `y = 3`. The table below explains the logical operators: |
| 34 | + |
| 35 | +| Operator | Description | Example | |
| 36 | +|--------------------|-------------------------------------|------------------------------| |
| 37 | +| && | and | (x < 10 && y > 1) is true | |
| 38 | +| == | or | (x == 5 || y == 5) is false | |
| 39 | +| == | not | !(x == y) is true | |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
3 | 45 | ## Conditions |
4 | 46 |
|
5 | 47 | The main conditional statement is <b>*if*</b>. Within this parameter, all the available <a href="../placeholders/" target="_blank">placeholders</a> and their objective JavaScript mappings can be used. |
|
0 commit comments