Private Class Fields (#) Playground

Mrs. Yanti’s savings house: #saldo sits in the back room only the class’s own code can enter. What happens when Dina’s outside script names acc.#saldo, and…

Why it matters

Real encapsulation: other code (or you, later) cannot tamper with internal state, and that state does not leak into Object.keys or JSON. Unlike _underscore (only a convention) and closures (private, but without a class). The foundation of safe modern classes.

The key idea

# is not a convention: it is privacy the language enforces

Common mistakes

Try it in this playground