Search⌘ K

Methods in Objects

Explore how to create and manage methods within JavaScript objects using the this keyword. Understand how this refers to the current object to access or update properties. Learn to implement object methods to return or modify data, enabling more modular and functional object-oriented programming in JavaScript.

An object contains properties, where the property value can either be a value or a function. In case the property is a function, it is referred to as an object method.

this Keyword

Let’s consider a scenario where you have an object named employee with the properties name, age and designation. Now you are required to write an object method display() that returns the designation of that employee. The first approach that comes to mind ...