Prototype

In JavaScript each object has link to the prototype of object. When object is creating it copying properties from its prototype. The prototype object also may have its own ptototype. This is often referred to as a prototype chain. The last object in this chain has prototype with null value.

Prototype has the constructor property, that defines a function for object creating.

The prototype allows add new properties to existing types and implement inheritance.

One other benefit of prototype is sharing functions between several objects for economy of memory. This is because when a method is defined using this.myMethod a new copy is created every time a new object is instantiated.

You can access to prototype via the prototype property of constructor like String.prototype. Or via the __proto__ property of object instance. Since ECMAScript 2015 you can use Object.getPrototypeOf to get prototype of object.

function Rect(w,h){this.width=w; this.height=h;}

Rect.prototype.area = function(){return this.width*this.height;}
    
var rect = new Rect(3,7); 

console.log(rect.area());
console.log(Object.getPrototypeOf(rect));
console.log(rect.__proto__);