Suggest an editImprove this articleRefine the answer for “Is it possible not to define a constructor?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)Yes, a constructor can be left undefined: if a class has no `constructor()`, JavaScript **automatically creates a default one**. In a class without inheritance that default constructor simply does nothing, and in a class that inherits another one, it calls `super()` on its own. **Key point:** a constructor becomes required only when an inheriting class adds its own fields or logic, in which case `super()` must be called manually as the first line, before using `this`.Shown above the full answer for quick recall.Answer (EN)Image## What Happens if There Is No Constructor If you don't define a `constructor()`, JavaScript **automatically creates one by default**. ### Example: ```javascript class User { greet() { console.log("Hi!"); } } const u = new User(); u.greet(); // Hi! ``` Under the hood, the engine creates **a constructor like this**: ```javascript class User { constructor(...args) { super(...args); // if there is a parent class } } ``` --- ## If a Class **Does Not Inherit** (No `extends`) Then the standard "empty" constructor simply does nothing: ```javascript class User {} // equivalent to: class User { constructor() {} } ``` --- ## If a Class **Inherits** From Another (`extends` Is Present) Then a **constructor is required only if you want to add logic and use** `this`. If there isn't one, the engine adds a constructor itself that calls `super()`. ```javascript class Animal { constructor(name) { this.name = name; } } class Dog extends Animal {} // Equivalent to: class Dog extends Animal { constructor(...args) { super(...args); } } const dog = new Dog("Rex"); console.log(dog.name); // Rex ``` --- ## Important: If You Add a Constructor in the Subclass Yourself You **must call** `super()` before using `this`, otherwise you get an error. ```javascript class Animal { constructor(name) { this.name = name; } } class Dog extends Animal { constructor(name, breed) { // super() must come first! super(name); this.breed = breed; } } ``` If you don't call it: ```javascript constructor(name, breed) { this.breed = breed; // ReferenceError: Must call super constructor before accessing 'this' } ``` --- ## Summary | Situation | Do You Need to Write `constructor()`? | | --- | --- | | Class without inheritance | Not needed | | Class inherits another one but adds no new behavior | Not needed | | Class inherits and adds its own fields | Needed (and must call `super()`) | | Logic must run when the instance is created (e.g., initialization, validation) | Needed |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.