JavaScript Getter (The get Keyword)

Example: This example describes the use of the lang() property to get the value of the language property.

Javascript




// Create an object:
const person = {
    name: "w3wiki",
    get lang() {
        return this.name;
    }
};
 
// Display data from the
//object using a getter
console.log(person.name);


Output

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.

Similar Reads

JavaScript Getter (The get Keyword)

Example: This example describes the use of the lang() property to get the value of the language property....

JavaScript Setter (The set Keyword)

...

Reasons to use Getters and Setters

Example: This example describes the use of the lang() property to set the value of the language property....

Data Quality

...

Contact Us