Setter

noun

say it: “SET-er” /ˈsɛtər/

A method marked with set that runs when code assigns a property, so it can check the new value before storing it.

What is Setter in JavaScript?

Setter — A method that validates or changes an object's stored value.

class Thermostat {
    #temperature = 20;

    get temperature() {
        return this.#temperature;
    }
}

In a sentence

  • “The setter refuses an age below zero, so pet.age = -3 throws an error.”

Level: Journeyman · More JavaScript terms at this level

Updated

In other subjects