Object Methods and 'this'

Objects can contain functions, which are then referred to as methods. The keyword this refers to the object that is calling the method.

const person = {
  name: "Bob",
  greet: function () {
    console.log(`Hi, I'm ${this.name}`);
  }
};

person.greet(); // Output: Hi, I'm Bob
← PrevNext →