The new Keyword in JavaScript: Constructors, Objects, and Prototypes

new Car("Tesla") — what actually happens?
Writing new Car("Tesla") looks like a single, simple step — call a function, get an object back. But behind that one line, JavaScript is quietly performing a specific, ordered sequence of steps that most developers use constantly without ever seeing spelled out. Understanding that sequence is exactly what turns constructor functions and prototypes from memorized syntax into something you genuinely understand.
What the new Keyword Does
The new keyword turns an ordinary function call into an object creation process. Calling a function normally just runs its code and returns whatever it returns:
function Car(brand) {
this.brand = brand;
}
Car("Tesla"); // just runs the function — this refers to something unexpected here, no object is createdCalling the exact same function with new behaves completely differently:
const myCar = new Car("Tesla");
console.log(myCar.brand); // "Tesla"new is what tells JavaScript: "treat this function as a constructor, and build me a new object from it" — the same function, used two fundamentally different ways depending on whether new is present.

Constructor Functions
A constructor function is simply a regular function written with the intention of being called with new, to produce new objects that share the same shape and behavior.
function Car(brand, year) {
this.brand = brand;
this.year = year;
}By convention, constructor function names start with a capital letter (Car, not car) — a widely followed signal to other developers that "this function is meant to be used with new," even though JavaScript itself doesn't enforce that capitalization rule technically.
Inside a constructor, this refers to the new object being built — which is exactly what makes the object-creation process (covered next) actually work.
Object Creation Process
When you write new Car("Tesla", 2024), JavaScript performs four distinct steps, in order:
Step 1: Create a new, empty object
// Conceptually:
const newObject = {};Step 2: Link that new object to the constructor’s prototype
// Conceptually:
newObject.__proto__ = Car.prototype;Step 3: Run the constructor function, with this bound to the new object
// Inside Car, `this` now refers to newObject
this.brand = "Tesla";
this.year = 2024;Step 4: Return the new object automatically
Unless the constructor explicitly returns a different object itself, new automatically returns the object that was just built and populated.

This is genuinely the entire process — no extra hidden magic. new is really just a convenient shorthand for these four specific, ordinary steps.
How new Links Prototypes
Every function in JavaScript automatically has a prototype property — an object that becomes the shared foundation for every instance created from that constructor.
function Car(brand) {
this.brand = brand;
}
Car.prototype.honk = function () {
console.log(`${this.brand} says beep!`);
};
const myCar = new Car("Tesla");
myCar.honk(); // "Tesla says beep!"Notice honk isn't defined inside the constructor itself — it's added to Car.prototype. Yet myCar.honk() still works, because Step 2 of the creation process linked myCar to Car.prototype — when JavaScript can't find honk directly on myCar, it looks up the prototype chain and finds it there instead.

This is also why adding a method to the prototype (rather than inside the constructor itself) is efficient: every instance shares the exact same honk function in memory, rather than each instance getting its own separate copy.
const car1 = new Car("Tesla");
const car2 = new Car("Toyota");
console.log(car1.honk === car2.honk); // true — same shared function, from the prototype