Objects have prototype and [[prototype]] property. [[prototype]] property is set at object creation time.

Every object (including functions) has this internal property called[[prototype]]. It can only be set at object creation time, either withnew, withObject.create, or based on the literal (functions default to Function.prototype, numbers to Number.prototype, etc.). It can only be read withObject.getPrototypeOf(someObject). There isnoother way to set or read this value.

Functions, in addition to the hidden [[prototype]] property, also have a property called prototype, and it is this that you can access, and modify, to provide inherited properties and methods for the objects you make.

The new keyword does 4 things:

  1. It creates a new object. The type of this object, is simply object.
  2. It sets this new object's internal, inaccessible, [[prototype]] property to be the constructor function's external, accessible, prototype object.
  3. It executes the constructor function, using the newly created object whenever this is mentioned.
  4. It returns the newly created object, unless the constructor function returns a non-primitive value. In this case, that non-primitive value will be returned.
Recommended articles: