The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

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

const car1 = new Car('Eagle', 'Talon TSi', 1993);

console.log(car1.make);
// expected output: "Eagle"

Syntax

Copy to Clipboard

new constructor[([arguments])]

Parameters

**constructorA class or function that specifies the type of the object instance.arguments**A list of values that the constructor will be called with.

Description

The new keyword does the following things:

  1. Creates a blank, plain JavaScript object.

  2. Adds a property to the new object (__proto__) that links to the constructor function's prototype object

    Note: Properties/objects added to the construction function prototype are therefore accessible to all instances created from the constructor function (using new).

  3. Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step).

  4. Returns this if the function doesn't return an object.