Skip to content

Commit b35db41

Browse files
committed
Add article about conditional comparators
1 parent d65d375 commit b35db41

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

conditional/comparators.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Comparators
2+
3+
Lets now focus on the conditional part:
4+
5+
```javascript
6+
if (country === "France") {
7+
...
8+
}
9+
```
10+
11+
The conditional part is the country followed by the three equal signs (`===`). Three equal signs mean that the condition tests if the variable country has the value you test against but also the correct variable (data)type. You can test conditions with double equal signs, too, but that would mean that `if(x == 5)` would be true for x being 5 and x being “5”. Depending on what your program is doing, this could make quite a difference.
12+
13+
Other conditional test:
14+
15+
* ```x > a```: is x bigger than a?
16+
* ```x < a```: is x less than a?
17+
* ```x <= a```: is x less than or equal to a?
18+
* ```x != a```: is x not a?
19+
* ```x```: does x exist?
20+
21+
22+
---
23+
24+
Add a condition to change the value of `a` to 10 if `x` is bigger than 5.
25+
26+
```js
27+
var x = 6;
28+
var a = 0;
29+
30+
31+
```
32+
33+
```js
34+
var x = 6;
35+
var a = 0;
36+
37+
if (x > 5) {
38+
a = 10;
39+
}
40+
```
41+
42+
```js
43+
assert(a == 10);
44+
```
45+
46+
---

0 commit comments

Comments
 (0)