Course contentsShow
← JavaScript
Lesson 740 of 2,72317. Prototypes and InheritanceFree lesson

Forgetting 'new': The Pitfall

See what happens when you call a constructor without 'new'—'this' binds incorrectly and no object is created.

Forgetting 'new': The Pitfall

You'll learn what goes wrong when you accidentally call a constructor function without the new keyword—and why it causes subtle bugs.

The Problem

When you call a constructor function without new, JavaScript treats it like a regular function call. This means:

  1. No new object is created — the automatic object creation step simply doesn't happen
  2. this binds incorrectly — instead of pointing to a new object, this follows regular function rules (often binding to the global object or undefined in strict mode)
  3. Properties get attached to the wrong place — any properties you set on this end up somewhere unexpected

Seeing It In Action

function Car(make, model) {
  this.make = make;
  this.model = model;
}

// Correct usage with 'new'
const myCar = new Car('Toyota', 'Camry');
console.log(myCar.make); // 'Toyota' ✓

// Forgetting 'new' — disaster!
const brokenCar = Car('Honda', 'Civic');
console.log(brokenCar); // undefined (no object returned!)
console.log(typeof brokenCar); // 'undefined'

// Even worse: properties leaked to global scope
console.log(make); // 'Honda' (polluted global!)
console.log(model); // 'Civic'

Think of new as the "construction permit" for building an object. Without it, you're just running code that tries to modify this without creating a proper container for those properties.

In strict mode, this fails more obviously because this is undefined, causing an error when you try to set properties on it.

Key Takeaway: Always use new when calling constructor functions—forgetting it prevents object creation and causes this to bind incorrectly, leading to subtle bugs or global pollution.