-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-booleans.html
More file actions
97 lines (93 loc) · 3.01 KB
/
06-booleans.html
File metadata and controls
97 lines (93 loc) · 3.01 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
<!DOCTYPE html>
<html>
<head>
<title>Booleans</title>
</head>
<body>
<script>
// console.log(typeof 'true'); //string
// console.log(typeof true); //boolean
// false
// console.log(3 > 5); //true
// console.log(3 < 5); //false
// console.log(3 === '5.00'); //false
// if (true) {
// console.log('hello');
// } //true
// if (false) {
// console.log('hello');
// } //false
// if (true) {
// console.log('hello');
// } else {
// console.log('else');
// }
// const age = 15
// if(age <= 16){
// console.log('you can drive');
// } else {
// console.log('you can not drive');
// } //true you can drive.
// if(30 <= 16){
// console.log('you can drive');
// } else if (15 >= 14) {
// console.log('almost there');
// }else {
// console.log('you can not drive');
// } //true you can not drive.
//and logical operator
console.log(true && false); //false
console.log(true && true); //true
console.log(false && false); //true
console.log(false && true); //false
console.log(0.2 >= 0 && 0.2 < 1 / 3);
//if the two or, any of the
// sides are true the result will be true
console.log(true || false);
//OR logical operater
//NOT operator flips the value of the boolean
//if the value is true it will be false and
//if the value is false it will be true
//console.log(!true); //false
//console.log(!false); //true
if (0) {
console.log('truthy'); //false
}
const cartQuantity = 5; //truthy value.
if (cartQuantity) {
console.log('cart has product')
}
console.log(!1); //false
console.log(!0); //true
console.log(0); //0
console.log(!-2); //false
console.log(!4); //false
if (cartQuantity > 0) {
console.log('cart has products');
}
//falsy values
// NAN: not a number : invalid calculation
// undefined: invalid number or don't have a value
// SHORT CUTS FOR THE IF STATEMENTS
// Ternerary operator
// 'trutty is the if statement'
// 'false is the else statement'
true ? 'trutty' : 'false';
const result = true ? 'trutty' : 'false';
// Gard operator !!
//and operator stops the execution of the code if the first value is false
true && console.log("hello"); //prints out the message hello
const maessage = false && console.log("hello");
console.log(maessage); //the value false will be saved inside the varaible
// any number posible from 1 to infinity is a truthy
// 0 is a falsy value
const maes = true && console.log("hello");
console.log(maes); //value will be undefined.
//dafault operator
const currency = 'EUR' || 'USD';
console.log(currency); //EUR
const currenc = undefined || 'USD';
console.log(currenc); //uUSD
</script>
</body>
</html>