Skip to content

Commit 75c4ef5

Browse files
committed
arrow func & this keyword
1 parent 09e3420 commit 75c4ef5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

js_functions/arrowfn.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const user = {
2+
username: "henry",
3+
price: 999,
4+
5+
welcomeMessage: function () {
6+
console.log(`${this.username}, welcome to our website!`);
7+
console.log(this);
8+
},
9+
};
10+
11+
user.welcomeMessage();
12+
user.username = "sam";
13+
user.welcomeMessage();
14+
15+
console.log(this); // Empty object in node, Window object in browser
16+
17+
const biscuit = () => {
18+
let username = "henry";
19+
//console.log(this); // {}
20+
};
21+
//biscuit();
22+
23+
// basic Arrow function
24+
// const addTwo = (num1, num2) => {
25+
// return num1 + num2;
26+
// };
27+
28+
// Implicit return
29+
const addTwo = (num1, num2) => num1 + num2;
30+
console.log(addTwo(4, 5)); // 9

0 commit comments

Comments
 (0)