-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
297 lines (208 loc) · 5.51 KB
/
app.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//------ String-------
// EXAMPLE ES5
// var name = "fikri";
// console.log("my name is " + name);
// // Example ES6
// var name6 = "Hani";
// console.log(`my name is ${name6}`);
//------ Var Let Const-------
// Example ES5
// var jobs = "architect";
// for (var i = 0; i<1; i++) {
// var jobs = "engineering";
// console.log (jobs)
// }
// console.log(jobs);
// Example ES6
// let jobs6 = "teacher";
// for(let i = 0; i<1; i++) {
// let jobs6 = "police";
// console.log(jobs6);
// }
// console.log(jobs6)
//------- Block vs IIFEs------
// Example ES5
// (function () {
// var name = "Ahmad";
// console.log(name);
// })()
// Example ES6
// {
// const name = "Zaki";
// console.log(name);
// }
//------- Arrow Function------
// var year = [1980,1990,1995]
// // Example ES5
// var ages5 = year.map(function (el) {
// return 2016-el;
// });
// console.log(ages5);
// // Example ES6
// var ages6 = year.map((el,index) => 2016-el);
// console.log(ages6);
//------- Arrow Function 2 ------
// var person = function (name,jobs,age) {
// this.name = name;
// this.jobs = jobs;
// this.age = age;
// }
// Example ES5
// person.prototype.work = function (work) {
// var nameWork = work.map(function(el){
// return "i am work at " + this.jobs + ", my last job is " +el
// }.bind(this));
// console.log(nameWork);
// }
// var work = ["small","vile","go","tham"]
// var andi = new person("andi","cost",20);
// andi.work(work);
//Example ES6
// person.prototype.work6 = function (work) {
// var nameWork6 = work.map(el => `i am work at ${this.jobs} , my last job is ${el}`)
// console.log(nameWork6);
// }
// const work = ["justice","league","avenger"];
// const rasya = new person("rasya","harpot",18);
// rasya.work6(work)
//------- Destructuring ------
// var jobs = {
// jobName: "programming",
// jobSallary: 20000000
// }
// Example ES5
// var name = ["hanif","rasya"]
// var hanif = name[0];
// var rasya = name[1];
// console.log(hanif,rasya);
// var jobName = jobs.jobName;
// var sallary = jobs.jobSallary;
// console.log(jobName,sallary);
// Example ES6
// const [hanif,rasya] = ["hanif","rasya"]
// console.log(hanif,rasya);
// const {jobName,jobSallary} = jobs;
// console.log(jobName,jobSallary)
//------- Spread Operator ------
// function addNames(a,b,c) {
// return a + b + c
// }
// Example ES5
// var names = ['fikri','ihsanul','abiyyu'];
// var names2 = addNames.apply(null,names);
// console.log(names2)
// Example ES6
// const name3 = addNames(...names);
// console.log(name3)
//------- Rest Operator ------
//Example ES5
// function names() {
// var arrNames = Array.prototype.slice.call(arguments,1)
// arrNames.forEach(function(el){
// console.log(el);
// })
// }
// names('sarah','hanifah');
//Example ES6
// function names6(...names) {
// names.forEach(el=>console.log(el));
// }
// names6('arif','widya')
// ------- Default Parameter --------
// Example ES5
// function number(number1, number2) {
// number1 === undefined ? number1 = 12 : number1 = number1;
// number2 === undefined ? number2 = 10 : number2 = number2;
// console.log(number1,number2);
// }
// number()
// Example ES6
// function number6(number1=12,number2=10) {
// console.log(number1,number2);
// }
// number6(23)
// --------Maps---------
// const age = new Map();
// age.set('question',"what is your age ?");
// age.set(1, 12);
// age.set(2, 10);
// console.log(age.get('question'));
// console.log(age.entries());
//--------Class----------
// Example ES5
// function people(name,year,job) {
// this.name = name;
// this.year = year;
// this.job = job;
// }
// people.prototype.born = function () {
// console.log(2016-this.year)
// }
// var nabil = new people ('nabil',1990,'teacher');
// nabil.born()
// Example ES6
// class people {
// constructor (name,year,job) {
// this.name = name;
// this.year = year;
// this.job = job;
// }
// calculateAge () {
// var age = 2019 - this.year;
// console.log(age);
// }
// static greeting () {
// console.log('Hi');
// }
// }
// const nabil = new people ('nabil',2002,'programmer');
// nabil.calculateAge();
// people.greeting();
//------- Subs Classes --------
// Example ES5
// function people(name,year,job) {
// this.name = name;
// this.year = year;
// this.job = job;
// }
// people.prototype.born = function () {
// console.log(2016-this.year)
// }
// var programmer = function(name,year,job,codingLanguage) {
// people.call(this,name,year,job);
// this.codingLanguage = codingLanguage;
// }
// programmer.prototype = Object.create(people.prototype);
// programmer.prototype.skill = function(Skill) {
// console.log('Javascript');
// }
// var nabil = new programmer ('nabil',1990,'java');
// nabil.born()
// nabil.skill();
// Example ES6
class people {
constructor (name,year,job) {
this.name = name;
this.year = year;
this.job = job;
}
calculateAge () {
var age = 2019 - this.year;
console.log(age);
}
static greeting () {
console.log('Hi');
}
}
class programmer extends people {
constructor (name,year,job,codingLanguage) {
super(name,year,job);
this.codingLanguage = codingLanguage;
}
skill() {
console.log(`My Skill is ${this.codingLanguage}`);
}
}
const nabil = new programmer ('nabil',2002,'programmer', 'C++');
nabil.calculateAge();
nabil.skill()