JavaScript new.target

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Inside a function or constructor, new.target is the constructor invoked by new. If the function was called without new, new.target is undefined.

JavaScript Syntax

JavaScript
function F() {
  console.log(new.target === F);
}
new F();
F();
Try it Editor

How It Works

  1. With new. new.target is F.
  2. Without new. new.target is undefined (false comparison).

Examples

Example 1 — Require new

Common guard pattern.

JavaScript
function Point(x) {
  if (!new.target) throw new TypeError("Call with new");
  this.x = x;
}
console.log(new Point(1).x);
Try it Editor

How It Works

  1. Guard ensures constructor use.

Example 2 — Subclass sees child

new.target is the derived class.

JavaScript
class A {
  constructor() { console.log(new.target.name); }
}
class B extends A {}
new B();
Try it Editor

How It Works

  1. Even in A's constructor, new.target is B.

Example 3 — See new

Creating instances.

JavaScript
console.log(new String("x").valueOf());
Try it Editor

How It Works

  1. new calls a constructor.

Frequently Asked Questions

It is a meta-property available in functions and constructors.
Arrow functions do not have their own new.target; they inherit from the surrounding function.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful