-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-Shortcut.js
95 lines (59 loc) · 1.8 KB
/
6-Shortcut.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
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
// truthy ===> 'string', 7, true, {}, [] -----------!!!
// falsy ===> '', 0, false, null, undefined -----------!!!
/* ------------------------------------------ */
// check truthy
let myVar = 5;
// check any truthy
if (myVar) {
myVar = myVar * 100;
}
else {
myVar = 0;
}
/* ------------------------------------------ */
// check falsy
let myMoney = 50;
// you check negative or falsy anything
if (!myMoney) {
}
/* ------------------------------------------ */
const money = 800;
let food;
if (money > 100) {
food = 'biriyani';
}
else {
food = 'cha biscuit';
}
/* ------------------------------------------ */
// ternary Operator -----!!!
let food1 = money > 100 ? 'biryani' : 'cha biscuit';
// console.log(food1);
let drink = (money > 100 && myVar > 100) ? 'coke' : 'filter water';
// console.log(drink);
/* ------------------------------------------ */
// number to string conversion -----!!!
const num1 = 52;
// console.log(num1);
const numStr = num1 + '';
// console.log(numStr)
/* ------------------------------------------- */
// string to number conversion -----!!!
const input = '560';
const inputNum = +input;
// console.log(inputNum);
/* ------------------------------------------- */
// ternary Operator -----!!!
let isActive = true;
const showUser = () => console.log('Display User');
const hideUser = () => console.log('Hide User');
// isActive ? showUser() : hideUser();
/* -------------------------------------------- */
// use && if the left side is true then right side will be executed -----!!!
isActive && showUser();
/* -------------------------------------------- */
// use || if the left side is false then right side will be executed -----!!!
isActive || hideUser();
/* -------------------------------------------- */
// toggle boolean -----!!!
isActive = !isActive;