You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try to understand the above comparisons with some logic. Remember without any logic might be difficult.
207
-
JavaScript is some how a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types.
207
+
JavaScript is some how a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result.
208
+
209
+
As rule of thumb, if a value is not true with == it will not be equall with ===. Using === is safer than using ===. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types.
208
210
209
211
### Logical Operators
210
212
@@ -278,7 +280,7 @@ console.log(count--) // 0
278
280
console.log(count) // -1
279
281
```
280
282
281
-
####Ternary Operators
283
+
### Ternary Operators
282
284
283
285
Ternary operator allows to write a condition.
284
286
Another way to write conditionals is using ternary operators. Look at the following examples:
@@ -32,7 +32,7 @@ Conditions can be implementing using the following ways:
32
32
- switch
33
33
- ternary operator
34
34
35
-
### If
35
+
### if
36
36
37
37
In JavaScript and other programming languages the key word _if_ use to check if a condition is true and to execute the block code. To create an if condition, we need _if_ keyword, condition inside a parenthesis and block of code inside a curly bracket({}).
38
38
@@ -62,7 +62,7 @@ if (isRaining) {
62
62
63
63
As you can see in the above condition, 3 is greater than 0 and it is a positive number. The condition was true and the block code was executed. However, if the condition is false, we do not see a result. The same goes for the second condition, if isRaining is false the if block will not be executed and we do not see an output. In order to see the result of the falsy condition, we should have another block, which is going to be _else_.
64
64
65
-
### If Else
65
+
### if else
66
66
67
67
If condition is true the first block will be executed, if not the else condition will be executed.
68
68
@@ -113,7 +113,7 @@ if (isRaining) {
113
113
114
114
The above condition is false, therefore the else block was executed. How about if our condition is more than two, we will use *else if* conditions.
115
115
116
-
### If else if else
116
+
### if else if else
117
117
118
118
On our daily life, we make decision on daily basis. We make decision not by checking one or two conditions instead we make decisions based on multiple conditions. As similar to our daily life, programming is also full conditions. We use *else if* when we have multiple conditions.
119
119
@@ -160,7 +160,23 @@ if (weather === 'rainy') {
160
160
161
161
### Switch
162
162
163
-
Switch is an alternative for **if else if else else**
163
+
Switch is an alternative for **if else if else else**.
164
+
The switch statement starts with a switch keyword followed by a parenthesis and code block. Inside the code block we will have different cases. Case block run if the value in the switch statement parenthesis match with the case vale. The break is to terminate and it does not go down after the condition is satisfied. The default block run if all the cases don't satisfy the condition.
165
+
166
+
```js
167
+
switch(caseValue){
168
+
case1:
169
+
// code
170
+
break
171
+
case2:
172
+
// code
173
+
break
174
+
case3:
175
+
// code
176
+
default:
177
+
// code
178
+
}
179
+
```
164
180
165
181
```js
166
182
let weather ='cloudy'
@@ -309,4 +325,4 @@ isRaining
309
325
310
326
🎉 CONGRATULATIONS! 🎉
311
327
312
-
[<< Day 3](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/03_Day/03_day_booleans_operators_date.md) | [Day 5 >>](#)
328
+
[<< Day 3](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/03_Day/03_booleans_operators_date.md) | [Day 5 >>](#)
0 commit comments