Skip to main content

Intro to JS OOP

Object-Oriented Programming (OOP) is a way to organize code around objects that bundle data and behavior. The goal is to model real-world entities, keep related logic together, and make reuse easier.

What is object-oriented programming?

In OOP:

  • Code is structured as objects with properties (data) and methods (behavior).
  • Core ideas include:
    • Encapsulation — hide internal details and expose a clear interface.
    • Reuse — share common behavior across multiple objects.
    • Modeling — represent real-world entities with state and actions.

OOP in JavaScript

  • JavaScript is multi-paradigm — you can mix objects, functions, and functional patterns.
  • Classes are modern syntax built on JavaScript’s prototype system (no deep dive here).
  • OOP is optional: use it when it improves clarity and structure, skip it when it doesn’t.

What this section covers

  • Classes and instances
  • Methods and this
  • Encapsulation (public vs private)
  • Inheritance
  • Static properties and methods
  • Classes vs plain objects
  • When to (and not to) use OOP

What this section does not cover

  • Prototype manipulation
  • Framework-specific OOP patterns
  • Advanced design patterns (Factory, Observer, etc.)