forked from bittu1040/JavaScript-Coding-and-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathES-practise.js
More file actions
139 lines (95 loc) · 1.71 KB
/
ES-practise.js
File metadata and controls
139 lines (95 loc) · 1.71 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
new ES features:JS advance topics
let const
default parameter for function
Arrow function
rest parameter
spread operator
for ..of
for ..in
string literals
Destructuring
modules
class and its ecosystem
symbol
generators and iterators
promise and async await
Map and Set, weakMap, weakSet
iterable objects
*/
//let const
// blocked scope
// we can access global variable using var keyword-- this is not recommended
// We can redeclare using var but we cant redeclare using let or const
// temporary dead zone
/*
a=10;
var a;
var a=10;
console.log(a);
console.log(globalThis.a)
let b=80;
b=90;
*/
//default parameter for function
/*
function sum(a,b=50){
return a+b;
}
console.log(sum(4,5));
*/
// arrow function
/*
let sum = (a, b) => a + b;
var name = "Ankur"
let obj = {
name: "bittu",
getName: function () {
return () => {
console.log(this);
return this.name;
}
}
}
console.log(obj.getName()());
*/
// rest parameter
/*
function rest(para1, para2, ...para3){
console.log(para1); // 3
console.log(para2); // 5
console.log(para3); // [7, 9, 11]
}
rest(3, 5, 7, 9, 11)
// spread operator
let arr1= [1,2,4,5,6,3];
rest(...arr1);
*/
// for -of and for-in
// for-of loop
/*
const arr = [1, 2, 3, 4, 5];
for (const element of arr) {
console.log(element);
}
// for-in loop
const obj = { a: 1, b: 2, c: 3 };
for (const key in obj) {
console.log(key, obj[key]);
}
*/
// string literals
/*
let a=10;
console.log(`value of a is ${a}`)
*/
// destrcuturing
let arr=[1,2,3,4];
let [a,b,c,d]= arr;
console.log(a);
console.log(b);
console.log(c);
let obj1={name:"bittu", age: 30};
let {name: name1, age} = obj1;
console.log(name1);
console.log(age);