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.

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

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

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