What is the this keyword in JavaScript?
this refers to the object that is calling the function.
- In an object method,
thisis the object before the dot. - In a normal function,
thisisundefined(strict mode) or the global object. - In an arrow function,
thisis taken from the surrounding code. - With
new,thisis the new object.
const user = {
name: "Robin",
show() { console.log(this.name); }
};
user.show();
Output:
Tutorials Class - Output Window
Robin
See The this keyword.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |