-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-arrow-functions.js
51 lines (38 loc) · 1.14 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
var names = ["Andrew", "Julie", "Jen"];
// names.forEach(function(name) {
// console.log("forEach", name)
// });
// names.forEach((name) => { //{} for multiple statements
// console.log("arrowFunc", name)
// });
// names.forEach((name) => console.log(name)); // single expression
// var returnMe = (name) => name + "!"; //automatically gets returned
// console.log(returnMe("Yannick"));
// var person = {
// name: "Yannick",
// greet: function() {
// names.forEach(function(name) { // returns undefined because this is updated
// console.log(this.name + " says hi to " + name)
// })
// }
// };
// person.greet();
// var person = {
// name: "Yannick",
// greet: function() {
// names.forEach((name) => { // returns Yannick because this is NOT updated
// console.log(this.name + " says hi to " + name)
// })
// }
// };
// person.greet();
// Challenge Area:
function add(a, b) {
return a + b;
}
var addStatement = (a, b) => {
return a + b;
};
var addExpression = (a, b) => a + b;
console.log(addStatement(1, 3));
console.log(addExpression(9, 0));