| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Bad_super_call | [Back] [Original] |
Get to know MDN better
The JavaScript exception "super() is only valid in derived class constructors" occurs when the super() call is used somewhere that's not the body of a constructor in a class with extends keyword.
SyntaxError: 'super' keyword unexpected here (V8-based) SyntaxError: super() is only valid in derived class constructors (Firefox) SyntaxError: super is not valid in this context. (Safari)
SyntaxError
The super() call is used to invoke the base constructor of a derived class, so the base class can initialize the this object. Using it anywhere else doesn't make sense.
super() can also be defined in an arrow function that's nested within the constructor. However, it cannot be defined in any other kind of function.
You cannot call super() if the class has no extends, because there's no base class to call:
class Base {
constructor() {
super();
}
}
You cannot call super() in a class method, even if that method is called from the constructor:
class Base {}
class Derived extends Base {
constructor() {
this.init();
}
init() {
super();
}
}
You cannot call super() in a function, even if the function is used as a constructor:
function Base(x) {
this.x = x;
}
function Derived() {
super(1);
}
Object.setPrototypeOf(Derived.prototype, Base.prototype);
Object.setPrototypeOf(Derived, Base);
You can call super() before calling any other method in the constructor:
class Base {}
class Derived extends Base {
constructor() {
super();
this.init();
}
init() {
//
}
}
You can call super() in an arrow function that's nested within the constructor:
class Base {}
class Derived extends Base {
constructor() {
const init = () => {
super();
};
init();
}
}
This page was last modified on May 22, 2026 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |