Methods in Objects
This lesson teaches about methods in objects, how to declare them, and using the "this" keyword to set and get values in methods.
We'll cover the following
As discussed earlier, an object contains properties where the property value can either be some 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 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:
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy