- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript this Keyword
JavaScript Scope & Hoisting
JavaScript this Keyword
The JavaScript
thiskeyword refers to the object that is running the current function.
Its value is decided when the function is called, not when it is written.
That single rule explains almost every surprise involving this.
Example
Example
javascript
const person = {
name: "Ada",
greet: function () {
return "Hello " + this.name;
}
};
console.log(person.greet());