-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-arrow-functions.js
More file actions
46 lines (40 loc) · 955 Bytes
/
example-arrow-functions.js
File metadata and controls
46 lines (40 loc) · 955 Bytes
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
// EXAMPLE: Anonymous functions vs arrow functions
// var names = ['Andrew', 'Julie', 'Jen'];
//
// names.forEach(function (name) {
// console.log('forEach', name);
// });
//
// names.forEach((name) => {
// console.log('arrowFunc', name);
// });
//
// names.forEach((name) => console.log(name));
// EXAMPLE: Implicit return values
// var returnMe = (name) => name + '!';
// console.log(returnMe('Andrew'));
// EXAMPLE: Unmodified this binding
// var person = {
// name: 'Andrew',
// greet: function () {
// names.forEach((name) => {
// console.log(this.name + ' says hi to ' + name)
// });
// }
// };
//
// person.greet();
// Challenge Area
function add (a, b) {
return a + b;
}
// console.log(add(1, 3));
// console.log(add(9, 0));
// addStatement
var addStatement = (a, b) => {
return a + b;
}
// console.log(addStatement(4, 7));
// addExpression
var addExpression = (a, b) => a + b;
console.log(addExpression(3, -2));