| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_derived_return | [Back] [Original] |
Get to know MDN better
The JavaScript exception "derived class constructor returned invalid value x" occurs when a derived class constructor returns a value that is not an object or undefined.
TypeError: Derived constructors may only return object or undefined (V8-based) TypeError: derived class constructor returned invalid value 1 (Firefox) TypeError: Cannot return a non-object type in the constructor of a derived class. (Safari)
TypeError
Typically, a constructor does not need to return anythingthe value of this is automatically returned when the class is constructed. A constructor can also return an object, and this object will override this as the newly constructed instance. However, returning something that's neither an object nor undefined is usually a mistake, because that value is ignored. In base classes and function constructors (using the function syntax), returning such a value is silently ignored, while in derived classes, it throws an error.
class Base {
constructor() {}
}
class Derived extends Base {
constructor() {
return 2;
}
}
new Derived(); // TypeError: derived class constructor returned invalid value 2
class Base {
constructor() {}
}
class Derived extends Base {
constructor() {
return { x: 1 };
}
}
new Derived(); // { x: 1 }
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 |