JavaScript classes

JavaScript classes, inheritance, and class syntax

Learn JavaScript classes with focused lessons on class syntax, constructors, methods, inheritance, static members, private and protected fields, extending built-in classes, instanceof, mixins, and prototypes.

Class lessons and concepts

  1. Constructor functions before classes

    Understand object construction with new before moving into class syntax and instance initialization.

    Outcome: Connect class constructors to the older function-based object model.

    • JavaScript constructor
    • new operator
    • object instances
    Study Constructor, operator "new"
  2. Prototype inheritance

    Study the prototype chain because JavaScript classes are built on top of prototypal inheritance.

    Outcome: Understand inherited methods before using class extends syntax.

    • prototype inheritance
    • prototype chain
    • prototypal inheritance
    Study Prototypal inheritance
  3. Function prototype

    Learn how constructor functions use prototype to share behavior across object instances.

    Outcome: See the mechanism that class methods compile down to conceptually.

    • function prototype
    • constructor prototype
    • shared methods
    Study F.prototype
  4. Class basic syntax

    Write class declarations with constructors, methods, fields, and reusable object blueprints.

    Outcome: Create readable class-based models for users, products, widgets, and services.

    • JavaScript classes
    • class syntax
    • constructor method
    Study Class basic syntax
  5. Class inheritance

    Use extends and super to build specialized classes from base classes without duplicating behavior.

    Outcome: Model related object types while keeping shared behavior in one place.

    • class inheritance
    • extends JavaScript
    • super JavaScript
    Study Class inheritance
  6. Static properties and methods

    Attach behavior to the class itself for factories, helpers, counters, configuration, and shared utilities.

    Outcome: Distinguish instance behavior from class-level behavior.

    • static methods
    • static properties
    • class utilities
    Study Static properties and methods
  7. Private and protected members

    Use privacy patterns and private fields to control internal state and prevent accidental outside access.

    Outcome: Design classes with clearer public interfaces and safer internal state.

    • private fields
    • protected properties
    • encapsulation
    Study Private and protected properties and methods
  8. Extending built-in classes

    Extend built-in types carefully and understand the tradeoffs of custom arrays, errors, and platform objects.

    Outcome: Know when built-in subclassing is useful and when composition is cleaner.

    • extend built-in classes
    • custom Error
    • subclass Array
    Study Extending built-in classes
  9. Instanceof and class checks

    Check whether values belong to a constructor or class hierarchy with instanceof and related patterns.

    Outcome: Validate class instances without confusing prototypes, primitives, and plain objects.

    • instanceof
    • class checking
    • constructor check
    Study Class checking: "instanceof"
  10. Mixins

    Compose behavior across classes with mixin patterns when single inheritance is too restrictive.

    Outcome: Share behavior across unrelated classes without forcing an inheritance tree.

    • JavaScript mixins
    • class composition
    • reusable behavior
    Study Mixins
  11. Custom errors

    Extend Error to create named error classes with clearer failure types and handling paths.

    Outcome: Create class-based error types for validation, network, and domain failures.

    • custom errors
    • extend Error
    • error classes
    Study Custom errors, extending Error
  12. Native prototypes

    Understand native prototypes so class code fits into JavaScript's broader inheritance model.

    Outcome: Reason about methods inherited from Array, Object, Function, and other built-ins.

    • native prototypes
    • built-in prototypes
    • prototype methods
    Study Native prototypes