# 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.

```javascript
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](https://www.ask-codey.com/glossary?category=javascript&level=3)

Updated: November 9, 2026

## In other subjects

- [Encapsulation in C#](https://www.ask-codey.com/glossary/encapsulation-c-sharp)
- [Encapsulation in Java](https://www.ask-codey.com/glossary/encapsulation-java)
- [Encapsulation in OOP](https://www.ask-codey.com/glossary/encapsulation-oop)
- [Encapsulation in Python](https://www.ask-codey.com/glossary/encapsulation)

Source: https://www.ask-codey.com/glossary/encapsulation-javascript
