Skip to content

Commit 5ab428e

Browse files
committed
index changed
1 parent 59d4935 commit 5ab428e

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

app/index.js

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
1-
//Template Strings
1+
//fat arrows
22

3-
function getMessage() {
4-
const year = new Date().getFullYear();
5-
return "The year is " + year;
6-
}
3+
const add = function(a, b) {
4+
return a+b;
5+
};
76

8-
console.log(getMessage());
7+
add(1, 2);
98

9+
//remove function key word add fat arrow after params
10+
const addFat = (a, b) => {
11+
return a+b;
12+
};
1013

11-
// difference is we use back ticks and then whereever we want a variable to appear we put it inside of the
12-
// ${variableNameHere}. This allows us to not have to use normal concatenation.
13-
// inside the ${} you don't just have to have a variable, you can do any JS expression so you can do math for
14-
//instance
15-
function getMessage() {
16-
const year = new Date().getFullYear();
17-
return `The year is ${year}`;
18-
}
14+
addFat(1, 2);
1915

20-
console.log(getMessage());
2116

22-
//PHP
23-
// $data = '{"device_id":"'.$device_id.'","guid":"'.$guid.'","username":"'.$username.'","}';
17+
//if single expression, you can remove the brackets and the return and, it will implicitly return
18+
const addFat1 = (a, b) => a+b;
2419

25-
data = '{"device_id":"' + device_id +'", "guid":"' + guid +'", "username":"' + username +'","}';
20+
addFat1(1, 2);
2621

27-
data = `{"device_id": "${device_id}", "guid": "${guid}", "username": "${username}", "} `;
2822

23+
const double = function(number) {
24+
return 2 * number;
25+
};
2926

30-
//don't do the following
31-
const year = 2016;
32-
const yearMsg = `${year}`;
33-
yearMsg;
27+
double(8);
3428

35-
//should just be
36-
const year = 2016;
37-
const yearMsg = year;
38-
yearMsg;
29+
//with a single argument coming in, you can also omit the () around it. like the following
30+
// const double1 = number => return 2 * number;
31+
//
32+
// double1(8);
33+
34+
const number = [1,2,3];
35+
36+
//using map this is how learned initially
37+
numbers.map(function(number) {
38+
return 2 * number
39+
});
40+
//this drops function and puts the fat arrow after argument. as only one arguement can drop ()
41+
//since a single expression, can remove {} and return so it becomes just this
42+
numbers.map(number => 2* number);
43+
44+
const team = {
45+
members: ['Jane', 'Bill'],
46+
teamName: 'Super Squad',
47+
teamSummary: function() {
48+
return this.members.map(function(member) {
49+
return `${member} is on team ${this.teamName}`
50+
})
51+
}
52+
};
53+
54+
console.log(team.teamSummary());

0 commit comments

Comments
 (0)