-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-arrows.js
41 lines (35 loc) · 881 Bytes
/
example-arrows.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
var names = ['Andrew', 'Julie', 'Jen'];
// names.forEach(function(name){
// console.log('for Each', name);
// });
//
// names.forEach((name) => {
// console.log('arrow func', name);
// });
//
// names.forEach((name) => console.log(name));
//
// var returnMe = (name) => name + '!';
// console.log(returnMe('Andrew'));
//One big difference btw anon functions and arrow functions:
//anon functions have a this binding
//whereas arrow functions take on their parent's this binding
// var person = {
// name: 'Andrew',
// greet: function() {
// names.forEach((name) => {
// console.log(this.name + ' says hi to ' + name);
// });
// }
// };
//
// person.greet();
function add(a, b) {
return a + b;
}
var addStatement = (a, b) => {
return a + b;
}
console.log(addStatement(4, 7));
var addExpression = (a, b) => a + b;
console.log(addExpression(3, -2));