Encapsulation
noun
say it: “en-KAP-syoo-LAY-shun” /ɪnˌkæpsjəˈleɪʃən/
Keeping an object's data inside it and letting other code change that data only through the object's own methods, so it can't be set to a bad value.
What is Encapsulation in JavaScript?
Encapsulation — Keeping an object's data behind its methods so it's changed the safe way.
class Thermostat {
#temperature = 20;
get temperature() {
return this.#temperature;
}
}
In a sentence
- “With encapsulation, the only way to change the token count is through addTokens, which refuses negative numbers.”
Level: Journeyman · More JavaScript terms at this level
Updated