-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruthy.js
44 lines (28 loc) · 784 Bytes
/
truthy.js
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
const userEmail = '[email protected]'
if (userEmail) {
console.log("Got user email");
} else {
console.log("Don't have user email");
}
// falsy values
// false, 0, -0, BigInt 0n, "", null, undefined, NaN
//truthy values
// "0", 'false', " ", [], {}, function(){}
// if (userEmail.length === 0) {
// console.log("Array is empty");
// }
const emptyObj = {}
if (Object.keys(emptyObj).length === 0) {
console.log("Object is empty");
}
// Nullish Coalescing Operator (??): null undefined
let val1;
// val1 = 5 ?? 10
// val1 = null ?? 10
// val1 = undefined ?? 15
val1 = null ?? 10 ?? 20
console.log(val1);
// Terniary Operator
// condition ? true : false
const iceTeaPrice = 100
iceTeaPrice <= 80 ? console.log("less than 80") : console.log("more than 80")