Data Quality
The Getters and Setters are used to secure better data quality. In the given example below, using the lang property, the lowercase value of the language is returned.
Example: This example uses the lang property and it returns the lowercase value of the language.
Javascript
const person = { language: "w3wiki" , get lang() { return this .language.toLowerCase(); } }; // Display data from the //object using a getter console.log(person.lang); |
w3wiki
JavaScript Object Accessors
There are two keywords that define the accessors functions: a getter and a setter for the fullName property. When the property is accessed, the return value from the getter is used. When a value is set, the setter is called and passed the value that was set.