Constructor

noun

say it: “kun-STRUK-ter” /kənˈstrʌktər/

The special method in a class, named constructor, that runs once when new builds an object and fills in its starting values.

What is Constructor in JavaScript?

Constructor — The special class method that initializes a newly created JavaScript object.

class Book {
    constructor(title) {
        this.title = title;
    }
}

const guide = new Book("JavaScript");

In a sentence

  • “The constructor sets each pet's name and age the moment new Pet("Mochi", 2) runs.”

Level: Journeyman · More JavaScript terms at this level

Updated

In other subjects