intermediate
When OOP fits JS and TS
Use OOP when identity, lifecycle, invariants, and polymorphic behavior matter more than simple data transformation.
OOP fits when identity, lifecycle, invariants, and polymorphic behavior dominate—domain entities, state machines, plugin registries, UI controllers with long-lived state. Functional pipelines excel at data transformation, parsing, and parallel maps over collections.
JS is multi-paradigm: prototypes under classes, first-class functions everywhere. TS adds types to either style without forcing inheritance.
On interviews: pick OOP vs functions for a shopping cart versus CSV import pipeline and justify.
Common pitfalls: Java-style hierarchies in a language favoring composition, classes as namespace holders, and OOP where plain functions plus types suffice.
The trade-off is familiar entity modeling versus idiomatic JS simplicity—match paradigm to change patterns.
Checklist:
- OOP for entities with identity and rules.
- Functions for stateless transforms.
- Avoid inheritance depth in JS codebases.