Skip to content

JavaScript new target | Metaproperty

  • by

JavaScript’s new target meta property detects whether a function or constructor was called using the new operator. The consists of the new keyword, a dot, and target property. The is available in all functions.

JavaScript new target

Simple example code determines at runtime whether a function or constructor was called using the new keyword or not.


Detect whether a function was called with new as a constructor.

function Foo() {
  if (! { throw 'Foo() must be called with new' }
  console.log('Foo instantiated with new')

new Foo()  // logs "Foo instantiated with new"
Foo()      // throws "Foo() must be called with new"
<!DOCTYPE html>
    function Person(name) {
      if (! {
        throw "Must use new operator with Person";
      } = name;

    try {
    } catch (e) {



JavaScript new target


   class Person {
    constructor(name) { = name;

  class Employee extends Person {
    constructor(name, title) {
      this.title = title;

  let john = new Person('John Doe'); 
  let lily = new Employee('Lily Bush', 'Programmer'); 

Do comment if you have any doubts or suggestions on this JS pseudo-property topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *