-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-arrow-functions.js
53 lines (41 loc) · 1.2 KB
/
example-arrow-functions.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
var names = ['Ling', 'Lian', 'Tom'];
// =============================================================
// names.forEach(function (name) {
// console.log('forEach', name);
// });
// names.forEach((name) => {
// console.log('arrowFunc', name);
// });
// names.forEach((name) => console.log(name));
// var returnMe = (name) => name + '!!';
// console.log(returnMe('Ling'));
// ==============================================================
// var person = {
// name: 'Sam',
// greet: function () {
// names.forEach(function (name) {
// console.log(this.name + ' say hi to ' + name)
// });
// }
// };
// var person = {
// name: 'Sam',
// greet: function () {
// names.forEach((name) => {
// console.log(this.name + ' say hi to ' + name)
// });
// }
// };
// person.greet();
// ===============================================================
function add (a, b) {
return a + b;
}
console.log(add(1, 3));
console.log(add(9, 0));
var addStatement = (a, b) => {
return a + b;
}
var addExpression = (a, b) => a + b;
console.log('addStatment(1, 3): ', addStatement(1, 3));
console.log('addExpression(9, 0): ', addExpression(9, 0));