Private Field

noun

say it: “PRY-vit FEELD” /ˈpraɪvət fiːld/

A field in a class whose name starts with # (read "hash"), which only code inside that class can read or change.

What is Private Field in JavaScript?

Private Field — A class field beginning with # that is accessible only inside its declaring class.

class Thermostat {
    #temperature = 20;

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

In a sentence

  • “The balance is a private field, #balance, so code outside the class can't set it to a million.”

Level: Journeyman · More JavaScript terms at this level

Updated