Object-Oriented JavaScript

JavaScript’s objects work differently from most languages you may know. These tutorials explain classes, constructors, fields, and methods, and the prototype chain that sits underneath them. You’ll learn how inheritance really works, how this gets its value, and when a class is the right tool or a plain object and a few functions would do.
Free Bonus: JavaScript Cheat Sheet
Variables, arrays, objects, functions, and async basics in one printable reference.
Get the Free Cheat Sheet »A clear mental model of objects makes JavaScript far less surprising. It helps you debug a method that lost its this, read a class hierarchy in someone else’s code, and judge whether the classes an AI assistant generated are a good design or just more code.
Yes, but it’s prototype-based. Objects inherit directly from other objects through the prototype chain. The class syntax added in ES2015 is a cleaner way to write the same prototype-based code.
A class is syntax for creating objects that share methods. Under the hood, those methods live on a prototype object, and every instance links to it. Understanding prototypes explains how classes, inheritance, and method lookup actually work.
In a regular function, this depends on how the function is called, not where it’s defined. Passing a method as a callback detaches it from its object. Arrow functions and bind() fix this to the value you expect.
Yes. Prefix a class field or method with #, as in #count, and it’s only accessible inside the class body. Unlike a naming convention, the language enforces this.
Use a class when you create many objects that share behavior and state, such as items in a game or connections in a server. For one-off records or configuration, a plain object is simpler and easier to read.
