-
Notifications
You must be signed in to change notification settings - Fork 0
/
es6-features.html
171 lines (152 loc) · 5.32 KB
/
es6-features.html
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Javascript Practice</title>
</head>
<body>
<h1 id="box">ES 6 Updates</h1>
<script>
/* THE LET KEYWORD */
// console.log('THE LET KEYWORD');
// var topic = "Javascript";
// if(topic)
// {
// var topic = "React";
// console.log('block', topic);
// var box = document.getElementById('box');
// for(let i = 0; i < 5; i++)
// {
// div=document.createElement('div');
// div.innerHTML = 'Box ' + i;
// div.onclick = function()
// {
// alert('This is box number ' + i);
// }
// box.appendChild(div);
// }
// }
// console.log('global', topic);
/* THE CONST KEYWORD */
// console.log('THE CONST KEYWORD')
// const constant='constant';
// console.log('Before ', constant);
// constant='variable';
// console.log('After ', constant);
/* TEMPLATE STRINGS / TEMPLATE LITERALS */
// console.log('TEMPLATE STRINGS / TEMPLATE LITERALS');
// function print(name, age)
// {
// console.log(`Hello ${name}, you are ${age} years old.`);
// }
// print('John', 25);
/* SEARCHING STRINGS */
// console.log('SEARCHING STRINGS');
// const str = 'Nun Roti Khayenge UP me bas jayenge, thik hai!';
// console.log(str.startsWith('Nun'));
// console.log(str.endsWith('thik hai!'));
// console.log(str.includes('UP'));
// console.log(str.includes('up'));
// console.log(str.indexOf('UP'));
// console.log(str.repeat(5));
// console.log(str.replace('UP', 'MP'));
// console.log(str.search('UP'));
/* SYMBOLS (Like Unique IDs) */
// console.log('SYMBOLS (Like Unique IDs)');
// const id = Symbol();
// const courseInfo = {
// title: 'Javascript',
// topics: ['ES6', 'ES7', 'ES8'],
// id: 'js-course'
// };
// courseInfo[id] = 123;
// console.log(courseInfo);
// console.log(courseInfo[id]);
// console.log(courseInfo.id);
/* MAPS */
// console.log('MAPS');
// let course = new Map();
// course.set('react', {description: 'ui'});
// course.set('jest', {description: 'testing'});
// console.log(course);
// console.log(course.react); // gives undefined
// console.log(course.get('react')); // gives {description: 'ui'}
// console.log(course.size);
// course.forEach((item)=>{
// console.log(item);
// });
/* SETS */
// console.log('SETS');
// let books = new Set();
// books.add('Think Like A Monk');
// books.add('The Alchemist');
// books.add('You Can Win');
// books.add('Think Like A Monk');
// books.add('think like a monk');
// console.log(books);
// console.log(books.size);
// console.log(books.has('The Alchemist'));
// books.delete('The Alchemist');
// console.log(books);
// books.forEach((book)=>{
// console.log(book);
// });
/* THE SPREAD OPERATOR */
// console.log('THE SPREAD OPERATOR');
// let cats = ['Milo', 'Meow'];
// let dogs = ['Dodge', 'Meow'];
// let animals1 = ['Whale', 'Shark', cats, dogs];
// let animals2 = ['Whale', 'Shark', ...cats, ...dogs];
// console.log(animals1);
// console.log(animals2);
/* DESTRUCTURING */
// console.log('DESTRUCTURING');
// let course = [
// 'one',
// 'two',
// 'three',
// 'four'
// ];
// let [title, , ...rest] = course;
// console.log(title);
// console.log(rest);
// // Doesn't work with objects, only arrays
/* SEARCHING ARRAYS WITH INCLUDES */
// console.log('SEARCHING ARRAYS WITH INCLUDES');
// let courses = ['one', 'two', 'three', 'four'];
// console.log(courses.includes('two'));
// console.log(courses.includes('five'));
// console.log(courses.includes('Two'));
/* ENHANCING OBJECT LITERALS */
console.log('ENHANCING OBJECT LITERALS');
function getID(name, age) {
return {
name, // equivalent to name: name,
age, // equivalent to age: age,
id: `${name}(${age})`
};
}
/* DESTUCTURING TO THE NEXT LEVEL */
// const Student = {
// name: 'John',
// age: 25,
// scores: {
// maths: 74,
// english: 63
// }
// };
// function getStudentInfo( { name, age} ) {
// console.log(`${name} is ${age} years old.`);
// }
// getStudentInfo(Student);
/* FOR/OF LOOP */
// console.log('FOR/OF LOOP');
// let topics = ['one', 'two', 'three', 'four'];
// for(let topic of topics)
// {
// console.log(topic);
// }
</script>
</body>
</html>