Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

new.target

new.target reveals whether the current function was called with new. It is undefined for regular calls and refers to the function during construction.

How it works

new.target is a special expression available inside function and class bodies. It is undefined for an ordinary call and identifies the constructor used for construction, allowing code to distinguish constructor mode from regular invocation.

Syntax

new.target

Returns

The expression evaluates to undefined for regular calls, or to the constructor function when called with new.

Key points

  • Use new.target to tell whether a function was invoked as a constructor.
  • A direct call produces undefined, while construction produces the called function.
  • This distinction supports constructor-call validation or compatibility behavior.
  • A function can redirect a regular call to a constructor call when needed.

Common mistakes

  • Outside constructor calls, new.target is undefined; do not treat it as a normal object property.
  • Using new.target outside a function or class body causes a syntax error.

Example: Accept regular and constructor calls

function User(name) {
  if (!new.target) return new User(name);
  this.name = name;
}

console.log(new User("Ada").name);

The function creates an instance whether it is called directly or with new.

When to use it

Constructor-mode detection

Detect whether a function is being used as a constructor.

Call normalization

Make a constructor function work with or without explicitly writing new.

Invocation validation

Reject or handle accidental regular invocation of constructor-style functions.

  • new
  • constructor

Source: Constructor, operator "new". Checked 2026-10-15.