-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-boolenas.html
More file actions
100 lines (77 loc) · 2.23 KB
/
Copy path06-boolenas.html
File metadata and controls
100 lines (77 loc) · 2.23 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Booleans</title>
</head>
<body>
<script>
true
false
/*console.log(typeof true);
console.log(3<5);
console.log(5=='5.00'); //this is true
console.log(5==='5.00'); // false
// if(true) {
// console.log('hello');
// }
if(true) {
console.log('hello');
} else {
console.log('else')
}
const age = 14;
if (age >=18 ) {
console.log('You can drive');
} else if (age>=14) {
console.log('Almost there');
} else {
console.log('You can not drive');
}
*/
// console.log(true && true); // and logical both shouldbe true
// console.log(true || false); // OR operator, either can be true
// console.log(0.2 >= 0 && 0.2 < 1/3);
// console.log(!true);
// truthy and falsy values
// if (0) {
// console.log('truthy');
// }
// const cartQuantity =5;
// if (cartQuantity) {
// console.log('cart has products')
// }
// console.log(!0); // this is true, as NOT operator flips '0' to a truthy value.
// console.log('text' / 5);
// let variable1;
// console.log(variable1);
const result = false ? 'hello' : 'bye' // ? as an if statement and ':'acts as an else statement.
console.log(result);
false && console.log('hello'); // short-circuits, and doesnt even need to run code on right
const message = 5 && 'hello';
console.log(message);
const currency = 'EUR' || 'USD';
console.log(currency);
const currency1 = undefined || 'USD'; // generally used to save a defaut value when user hasnt defined any value. hence called the default operator.
console.log(currency1);
// simplified version:
// let currency;
// if(!condition) {
// currency = 'USD'
// }
const age = 2;
let discount;
if(age<=6 || age>=65) {
discount = true;
} else {
discount = false;
}
console.log(discount);
//using if-else shortcut
const isHoliday= true;
const discount1 = true ? (age<=6 || age>=65) && isHoliday : false;
console.log(discount1);
</script>
</body>
</html>