Course contentsShow
← JavaScript
Lesson 585 of 2,72314. The 'this' KeywordFree lesson

Constructor Forgetting 'new'

What happens when a constructor is called without 'new', and how 'this' points to the global object.

Constructor Forgetting 'new'

You'll learn what happens when you call a constructor function without the new keyword, and how it causes this to unexpectedly point to the global object.

The Problem

When you define a constructor function (meant to be called with new), JavaScript doesn't require you to use new. If you forget it and call the constructor like a regular function, this inside that function follows the normal function call rules — which means it points to the global object (or undefined in strict mode).

Think of it like a recipe labeled "for baking" that you accidentally follow on the stovetop. The instructions still run, but they operate on the wrong context, causing chaos.

function Person(name) {
  this.name = name; // Sets property on whatever 'this' is
}

const john = new Person('John'); // Correct: 'this' is new object
console.log(john.name); // "John"

const jane = Person('Jane'); // WRONG: forgot 'new'
console.log(jane); // undefined (function returns nothing)
console.log(window.name); // "Jane" (polluted global!)

What Actually Happens

Without new, the function executes as a normal function call. The implicit binding rule makes this point to the global object (window in browsers). So this.name = name accidentally creates a global variable instead of a property on a new instance.

In strict mode, this would be undefined, and trying to set this.name would throw an error — which is actually better because it fails loudly rather than silently corrupting the global scope.

'use strict';
function SafePerson(name) {
  this.name = name; // TypeError: Cannot set property 'name' of undefined
}

const oops = SafePerson('Oops'); // Crashes immediately

Key Takeaway: Forgetting new when calling a constructor causes this to bind to the global object (non-strict) or undefined (strict), accidentally creating global variables or throwing errors instead of creating a new instance.