Getter & Setter Playground

Yanti at the savings house’s door is the rupiah accessor: the getter counts the coins in the window, the setter turns rupiah into coins. What happens when the…

Why it matters

Getters/setters keep derived values always in sync (fullName, a cart total) and can validate input on write, without calling a method. They are used in classes, reactive stores (Vue, MobX), and clean object APIs.

The key idea

getter/setter = a property that quietly runs a function, accessed without parentheses

Common mistakes

Try it in this playground