What the 'new' Operator Does
You'll learn the four automatic steps JavaScript performs when you use the new keyword with a constructor function.
The Core Idea
When you write new SomeFunction(), JavaScript doesn't just call the function—it performs a choreographed sequence of four steps behind the scenes to create and configure a new object. Understanding these steps demystifies constructor functions and how instances get connected to prototypes.
The Four Steps of 'new'
Step 1: Create an empty object
JavaScript creates a brand new, empty object: {}.
Step 2: Link the prototype
The new object's [[Prototype]] (accessible via __proto__) is set to point to the constructor function's prototype property. This establishes the prototype chain.
Step 3: Bind 'this'
The constructor function is called with this bound to the new object. Any properties or methods you assign to this inside the function become own properties of the new object.
Step 4: Return the object
If the constructor doesn't explicitly return an object, JavaScript automatically returns the newly created object. (If you do return an object explicitly, that object is returned instead.)
Example Flow
function Person(name) {
this.name = name; // Step 3: 'this' is the new object
}
const user = new Person('Alice');
// Step 1: {} created
// Step 2: user.__proto__ → Person.prototype
// Step 3: Person called with this = new object, this.name = 'Alice'
// Step 4: new object returned automatically
Key Takeaway: The new operator automates object creation, prototype linking, this binding, and returning—transforming a regular function into a constructor that produces properly connected instances.