I read previously that any object has a prototype, which is an object which means it has a prototype=> which itself object I hope you see where it’s heading
the question here, the prototype chain terminology meant by this chain or the inheriting properties from other objects?
Let’s say we have a Duck
which has a prototype of Bird
, which has a prototype of Animal
, which has a prototype of Object
. That’s a prototype chain. When you look up properties on Duck, it will follow the prototype chain all the way down to Object
to find it. When a property is found further down the prototype chain, we call it an inherited property.
As for the prototype chain, it’s not endless; it does eventually end. The prototype of Object is {}
which is the representation of an empty object without any prototype. You can test this in node by seeing that Object.prototype.prototype
is undefined.
1 Like