Prototypes vs classes
ES6 classes are syntactic sugar over prototype-based inheritance:
class A {}
console.log(Object.getPrototypeOf(rex) === Dog.prototype);
// true - instances share the prototype chain
Every instance's prototype points to the class's prototype object, which holds shared methods. Inheritance chains prototypes: a subclass instance's prototype has the parent's prototype in its chain. Classes just make this readable.
Encapsulation trade-offs
Choose the right encapsulation level:
class Bank {
#balance = 0; // private
get balance() { return this#balance; } // read-only via getter
deposit(amount) { this#balance += amount; }
}
#private gives real privacy but is verbose. The _ prefix is conventional only, nothing stops access. Use getters/setters to expose a controlled API while keeping state hidden.