JavaScript Object Accessors Last Updated : 26 Jul, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. 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: "geeksforgeeks", get lang() { return this.name; } }; // Display data from the //object using a getter console.log(person.name); Outputgeeksforgeeks JavaScript Setter (The set Keyword)Example: This example describes the use of the lang() property to set the value of the language property. JavaScript // Create an object: const person = { name: "geeksforgeeks", set lang(value) { return this.name; } }; // Display data from the //object using a getter console.log(person.name); Outputgeeksforgeeks Note: Getters and Setters are not supported in Internet Explorer 8. Reasons to use Getters and SettersThe syntax for properties and methods are equal.Used for doing things behind the scenes.They can secure better data quality.The syntax of this is simpler.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: "Geeksforgeeks", get lang() { return this.language.toLowerCase(); } }; // Display data from the //object using a getter console.log(person.lang); Outputgeeksforgeeks Comment More infoAdvertise with us Next Article JavaScript Object Constructors A adeshsingh1 Follow Improve Article Tags : JavaScript Web Technologies javascript-object Similar Reads JavaScript Object Constructors An object is the collection of related data or functionality in the form of key. These functionalities usually consist of several functions and variables. All JavaScript values are objects except primitives. const GFG = { subject : "programming", language : "JavaScript",}Here, subject and language a 4 min read TypeScript Accessor TypeScript accessors, through get and set methods, offer controlled access to object properties, enhancing encapsulation, validation, and custom logic. By using accessors, you can manage how properties are accessed and modified, supporting a more robust object-oriented design in your classes.Getters 3 min read Anonymous Object in Java In Java, an anonymous object is an object that is created without giving it a name. Anonymous objects are often used to create objects on the fly and pass them as arguments to methods. Here is an example of how to create and use an anonymous object in Java. Example:Java import java.io.*; class Perso 2 min read Object Model in Java The object model is a system or interface which is basically used to visualize elements in terms of objects in a software application. It is modeled using object-oriented techniques and before any programming or development is done, the object model is used to create a system model or an architectur 8 min read Non-Access Modifiers in Java Modifiers are specific keywords present in Java using which we can make changes to the characteristics of a variable, method, or class and limit its scope. Java programming language has a rich set of Modifiers. Modifiers in Java are divided into two types - Access Modifiers and Non-Access modifiers. 12 min read Understanding Classes and Objects in Java The term Object-Oriented explains the concept of organizing the software as a combination of different types of objects that incorporate both data and behavior. Hence, Object-oriented programming(OOPs) is a programming model, that simplifies software development and maintenance by providing some rul 10 min read Like