-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlFlow.js
More file actions
100 lines (41 loc) · 1.3 KB
/
ControlFlow.js
File metadata and controls
100 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
if(55<30){
console.log("Correct");
}
else{
console.log("Wrong");
}
if(false === []){
console.log("Correct");
}
else{
console.log("Wrong");
} //This condition will always return 'false' since JavaScript compares objects by reference, not value.
let balance = 500;
(balance > 500)? console.log("true") : console.log("false");
if(false == []){
console.log("Correct");
}
else{
console.log("Wrong");
}
if([]){
console.log("Correct");
}
else{
console.log("Wrong");
}
// Expression Type Result Reason
// false == [] loose == true Both coerced to 0
// if ([]) truthiness true Non-empty object (array) is truthy
if(''){ // falsy value
console.log("Correct");
}
else{
console.log("Wrong");
}
let val = 10 ?? 15
console.log(val); // 10
let val1 = null ?? 22
console.log(val1); // 22
let val2 = undefined ?? 25
console.log(val2); // 25