This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.



Smartphone icons created by Freepik - Flaticon

JS Getters and Setters

Getters and setters allow you to get and set properties via methods.

This example uses a lang property to set the value of the language property.

// Create an object:
const person = {
  firstName: "John",
  lastName: "Doe",
  language: "NO",
  set lang(value) {
    this.language = value;
  }
};

// Set a property using set:
person.lang = "en";

// Display data from the object:
document.getElementById("demo").innerHTML = person.language;