Methods in Objects

In this lesson, we will learn about methods in objects, how to declare them, and how to use the "this" keyword to set and get values in methods.

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 is something like this:

Get hands-on with 1400+ tech skills courses.