Getter
noun
say it: “GET-er” /ˈɡɛtər/
A method marked with get that runs when code reads a property, so ship.shields can return a hidden value or work one out.
What is Getter in JavaScript?
Getter — A method that returns an object's stored value.
class Thermostat {
#temperature = 20;
get temperature() {
return this.#temperature;
}
}
In a sentence
- “I added a getter so other code can read pet.age even though the real value is private.”
Level: Journeyman · More JavaScript terms at this level
Updated