Skip to content

Commit 125313d

Browse files
author
Wcoder547
committed
this keyword
1 parent 6a708ca commit 125313d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

this_keyword.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const person = {
2+
name: "waseem",
3+
greet: function () {
4+
console.log("hello" + this.name + "!");
5+
},
6+
greet_callback: () => {
7+
console.log("hello" + this.name + "!"); //arrow function dont have the the value of this .
8+
// enclosing scope is the global context, where this does not refer to the person object.
9+
},
10+
};
11+
12+
person.greet();
13+
person.greet_callback();
14+
15+
// this {} in node
16+
// this (window) in browser

0 commit comments

Comments
 (0)