JavaScript Prototypes Made Simple 🚀

This isn’t the same as class inheritance in other languages.

The actual definition of prototypal inheritance is one object attempting to access the properties of another object.

Prototype:

When an object is created, the JS Engine assigns it a hidden property—an object denoted by [[__proto__]]—and attaches it to the newly created object.

To access these hidden properties, we can use [[__proto__]]. This is the object where all the methods and properties are attached.

arr.__proto__ is an object, which is equivalent to Array.prototype.

arr.__proto__.__proto__ is known as the prototype chain.

arr.__proto__

Array.__proto__

Object.__proto__

null