-
Notifications
You must be signed in to change notification settings - Fork 0
/
truthy.js
40 lines (31 loc) · 854 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
const userEmail = "[email protected]"
// if (userEmail) {
// console.log(`U got user email ${userEmail}`);
// } else {
// console.log(`don't have user email`);
// }
// Falsy values
false, 0, -0, BigInt, 0n, "", null, undefined, NaN
// Truthy values
// All true values not in false
// "0", 'false'," ", [], {},function(){}
// check array true
const users = [];
if (users.length === 0) {
console.log(`Array is empty`);
}
// check object
const emptyObj = {};
if (Object.keys(emptyObj).length === 0) {
console.log(`Object is empty`);
}
// Nullish Coalescing operation (??) null and undefined
let val;
// val = 5 ?? 10
// val = null ?? 10
val = undefined ?? 115
console.log(val);
// ternary Operation
// condition ? true : false
const tea = 100
tea < 80 ? console.log("Tea Price less than 80") : console.log("Tea Price more than 80")