Getter and Setter are introduced in the ECMAScript 5. In JavaScript, Getter and Setter are the most powerful property to set the values of the object and you want to get the value which depends on the other values in the object. We need to use get and set keyword at the start of the method when we are declaring the getter and setter method. Getter and setter is the accessor property rather than the method. For example, you have a customer object with the first name and last name in the object and you want to get the value of the customer, then get the method will provide you the complete name of the customer.

In this we did not need to call the getter method as a function, We just need to use it as a variable of the object only.
In this, If you have created a getter method only then we can get the value of the object only, We can not set the values by declaring the setter method in the object.

To make it work, We need to define the setter method as well.

As we can check that fullname is virtual property of the object, With the help of the getter and setter, it is readable and writeable now.
Be the first to comment.