Prototype in JavaScript

Ayesha Malik
2 min readJan 17, 2021

--

The prototype is an object that is associated with every function and object by default in JavaScript, where the function’s prototype property is accessible and modifiable and the object’s prototype property is not visible.

Each object has a private property that holds a link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype and acts as the final link in this prototype chain. Nearly all objects in JavaScript are instances of Object, which sits on the top of a prototype chain.

Prototypical Inheritance

We use a JavaScript prototype to add new properties and methods to an existing object constructor. rabbit.moves check the moves property in its own definition, Since we set the __proto__ property to animals. It is checking in its parent prototype seeing is there any value related to the rabbit.moves key and if yes it returns the value and this concept is known as Prototypical Inheritance.

--

--

Ayesha Malik

I’m a full-time software engineer who loves sharing knowledge to help others become better developers.