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"
Copy to Clipboard
new constructor[([arguments])]
**constructor
A class or function that specifies the type of the object instance.arguments
**A list of values that the constructor
will be called with.
The new
keyword does the following things:
Creates a blank, plain JavaScript object.
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
).
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).
Returns this
if the function doesn't return an object.