Object methods are actions that can be executed on objects, defined as functions stored within the object’s properties.
Property |
Value |
firstName |
John |
lastName |
Doe |
age |
50 |
eyeColor |
blue |
fullName |
function() {return this.firstName + ” ” + this.lastName;} |
Example
const person = { firstName: “John”, lastName: “Doe”, id: 5566, fullName: function() { return this.firstName + ” “ + this.lastName; } }; |
In the example, this
refers to the person object, with this.firstName
and this.lastName
representing the person’s firstName and lastName properties.