Prototypes. One of the most important topics in JavaScript and one that is regularly visited in JavaScript interviews. In this article, we will study prototypes in detail. So, let’s get started.

Let’s speak of an analogy before we dive deep into the concept of prototypes in JavaScript.

Every year, industries come up with new products which do not reach the consumer’s table. However, some of the outstanding features become parts of the upcoming products that the company releases. Hence, you can assume that the unreleased products serve as a prototype to the released products.

Now that you get the idea, time to dive in deep.

What are Objects in JavaScript?

Objects marry state and behavior into one entity. JavaScript is full of objects, for example, Array, String, and functions too are considered objects. Let’s consider the Array object. It has in-built methods such as pop() , push() , length(), etc .

When we define an ‘array’ here, we see that it automatically inherits the methods push(), length, pop(). Well, this is because of _prototypes. _Tada!

By definition, “In JavaScript, every object holds a reference to a superior object from which it inherits its properties. This superior object is called a prototype and this behavior is referred to as prototypal inheritance. The prototypal inheritance happens via a prototype chain.”

#computer-science #interview #coding #javascript

What are Prototypes in JavaScript? — JavaScript Interview Series
1.25 GEEK