Course contentsShow
← JavaScript
Lesson 755 of 2,72318. ClassesFree lesson

Comparing Class Syntax to Constructor Functions

See side-by-side how class syntax translates to traditional constructor function and prototype patterns.

Comparing Class Syntax to Constructor Functions

You'll learn how modern class syntax maps directly to the traditional constructor function pattern you already know.

The Same Engine, Different Appearance

Classes in JavaScript are syntactic sugar—they don't introduce new object-oriented mechanisms. Under the hood, they compile down to the same prototype-based system. Let's see the two approaches side-by-side:

Constructor Function Pattern:

function Car(brand, model) {
  this.brand = brand;
  this.model = model;
}

Car.prototype.start = function() {
  return `${this.brand} ${this.model} is starting`;
};

const myCar = new Car('Toyota', 'Camry');

Class Syntax (Equivalent):

class Car {
  constructor(brand, model) {
    this.brand = brand;
    this.model = model;
  }

  start() {
    return `${this.brand} ${this.model} is starting`;
  }
}

const myCar = new Car('Toyota', 'Camry');

Both create objects with identical structure: instance properties (brand, model) stored directly on the object, and methods (start) stored on Car.prototype.

Key Differences in Practice

While functionally equivalent, classes offer clearer syntax:

  • The constructor method replaces the function body
  • Methods are written without the function keyword or prototype assignment
  • Everything lives in one tidy block
  • Classes cannot be called without new (constructor functions can, causing bugs)
  • Classes are not hoisted (constructor functions are)

Think of classes as a cleaner blueprint format for the same underlying machine.

Key Takeaway: Class syntax and constructor functions produce the same prototype-based objects—classes just provide a more structured, error-resistant way to write them.