Wrote about operators and fixed a faulty example (#23950)
This commit is contained in:
@ -15,6 +15,9 @@ if (condition) {
|
||||
}
|
||||
```
|
||||
|
||||
The conditions can be as simple as just checking booleans, but you can also check the value of variables using operators. One of the most commonly used operators is the equality operator, "==". It checks if two values are equal to each other. Note that there are two equal signs and not just one. This is because of the fact that one equal sign would set the first value to equal the second, not compare them.
|
||||
|
||||
Some other common operators are the greater/smaller than operator (> and < respectively) and the not equal to operator (!=).
|
||||
|
||||
Multiple `if...else` statements can be chained to create an `else if` clause. This specifies a new condition to test and can be repeated to test multiple conditions, checking until a true statement is presented to execute.
|
||||
|
||||
@ -64,8 +67,8 @@ const num = someCondition ? 1 : 2;
|
||||
## Examples
|
||||
|
||||
**Using** `if...else`:
|
||||
```javascript
|
||||
|
||||
```javascript
|
||||
// If x is equal to 5, then the condition is TRUE. This results in z being set to 7 and q being set to 42.
|
||||
// If x does not equal to 5, then the condition is FALSE. This results in z being set to 19.
|
||||
if (x == 5) {
|
||||
@ -74,7 +77,6 @@ if (x == 5) {
|
||||
} else {
|
||||
z = 19;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**Using** `else if`:
|
||||
|
Reference in New Issue
Block a user