-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrowfunctions.js
More file actions
50 lines (35 loc) · 1.13 KB
/
arrowfunctions.js
File metadata and controls
50 lines (35 loc) · 1.13 KB
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
// Arrow Functions
//1. makes functions more concise(which means it is clear)
//2. allows us to do implicit returns allows us to write one liners
//3. doesnt rebind the value of this when using arrow functions inside another function
function sum(a, b) {
return a + b;
}
console.log(sum(10, 5));
// to create a arrow function create a variable and store it in there
// the => is an implicit return and only returning a single value.
// you can get rid of the return keyword.
/*const sumBodyOnceToldMe = (a, b) => {
return a + b;
}
// allows not to use function anymore
console.log(sumBodyOnceToldMe(12,8));*/
//const sumBodyOnceToldMe = (a, b) => a + b;
function eatPie(r) {
const PI = 3.14;
return PI * r * r;
}
const pieEater = r => Math.PI * r * r;
/*{
const PI = 3.14;
return PI * r * r;
}*/
console.log(eatPie(12));
**********************************************************************************
function randomNum() {
return Math.random();
}
const randomNumber = () => Math.random();
console.log(randomNumber());
// can use these when you are using .map, .filter, and last .reduce.
// can use arrow functions in objects.