The ‘this’ keyword in JavaScript is used to refer to the object that the current context belongs to. It can be used to refer to the object that owns the current code or method.

For example:

let person = {
name: ‘John’,
age: 30,
getInfo: function() {
console.log(`Name: ${this.name}, Age: ${this.age}`);
}
};

person.getInfo(); // Outputs: Name: John, Age: 30

Leave a Reply

Your email address will not be published. Required fields are marked *