Classes & Inheritance Drills
Use classes to bundle state with behaviour. Constructors, methods, static, getters, inheritance, and private fields with #.
Step 1 of 7
Why classes exist
You can model anything with plain objects and functions — but once a thing has both state and behaviour tied together, classes give you a clean shape for them.
Real-world examples you have already used:
- Every built-in
Errorin the browser is a class.TypeError,RangeError, and your own custom errors allextend Error. - The DOM’s
EventTarget,HTMLElement, andHTMLInputElementare a class hierarchy. - Three.js scenes, React class components, and most game engines are class-heavy.
This lesson is a tour of the syntax in the order you’ll need it: declaration, methods, static, getters/setters, extends/super, and private fields with #.
Think of it this way: A class is a blueprint. The constructor is the assembly line — given some parts (the arguments), it builds an instance with state and methods baked in.
Learn more on MDN