Utilizor
Contact Us

Object Methods

Functions stored as object properties.

Object Methods

Objects can also have methods.

Methods are actions that can be performed on objects.

Methods are stored in properties as function definitions.

const person = { firstName: "John", lastName: "Doe", id: 5566, fullName: function() { return this.firstName + " " + this.lastName; } };

In a function definition, this refers to the "owner" of the function.

Example

name = person.fullName();