JS Built-ins
Prototypesintermediate

Prototypes β€” Chain traversal with getPrototypeOf

πŸ“– Usage Example
class Animal {}
class Dog extends Animal {}
const d = new Dog();
d instanceof Dog; // true
d instanceof Animal; // true

instanceof traverses the prototype chain β€” a Dog is also an Animal.

Walking the Prototype Chain

The prototype chain is a linked structure. Each object has a prototype, which has its own prototype, forming a chain. You can walk this chain using Object.getPrototypeOf().

Challenge: Traverse the prototype chain starting from an object to understand how objects are linked together.

πŸ’‘ Hints (2)
  • β€’ Each call to Object.getPrototypeOf moves up one level in the chain
  • β€’ Eventually the chain reaches null (after Object.prototype)