Getters and Setters
Getters and setters let you define properties that execute code when they are read or written, while presenting a clean property access syntax to callers. They are defined with the get and set keywords in a class body or object literal.
Getters
A getter is a method that is called when its property is accessed. Define it with get propertyName() { }. It must not take any parameters and should return a value. Use getters for computed or derived properties — values that depend on other state.
Setters
A setter is called when its property is assigned. Define it with set propertyName(value) { }. It takes exactly one parameter. Use setters to validate or transform values before storing them.
Backing Store Pattern
Getters and setters typically store the actual value in a private backing field (using a private field #field or a naming convention like _field) to avoid infinite recursion when the getter/setter accesses the same property name.