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

super() Must Come First

Why super() must be called before accessing 'this' in the child constructor.

super() Must Come First

You'll learn: Why you must call super() before using this in a child class constructor.

The Rule

When your child class has a constructor, JavaScript enforces a strict requirement: you must call super() before you can access or assign to this. Trying to use this before super() will throw a ReferenceError.

Why This Rule Exists

Think of it like building a house on a foundation. The parent class's constructor sets up the foundation (initializing inherited properties and structure). You cannot start building your custom rooms (child properties) until that foundation exists.

When you call super(), JavaScript:

  1. Creates the instance object
  2. Runs the parent constructor to set up inherited properties
  3. Returns control to the child constructor so you can customize this

If you try to use this before super(), there's literally no object created yet for this to refer to!

Example

class Animal {
  constructor(name) {
    this.name = name;
  }
}

class Dog extends Animal {
  constructor(name, breed) {
    // ❌ This will throw an error:
    // this.breed = breed; // ReferenceError: Must call super first!
    
    // ✅ Correct order:
    super(name);         // Call parent constructor first
    this.breed = breed;  // Now you can use 'this'
  }
}

const buddy = new Dog('Buddy', 'Golden Retriever');

Key Takeaway: In a child class constructor, always call super() as your very first statement before accessing this — the parent must initialize the object before you can customize it.