🟢 EasyObjects📖 Theory Question

How does prototypal inheritance work in JavaScript?

💡

Hint

Every object has a [[Prototype]] link — property lookup walks the chain

Full Answer

Every JS object has an internal [[Prototype]] link. Property lookup walks up the chain until found or null.

const animal = { speak() { return '...'; } };
const dog = Object.create(animal); // dog's proto = animal
dog.name = 'Rex';
dog.speak(); // Found on chain → '...'

// ES6 class is sugar over this
class Dog extends Animal {
  speak() { return 'Woof!'; }
}
💡 Use hasOwnProperty() to check if a property is directly on the object vs inherited.

More Objects Questions

🟢 EasyWhat is the difference between shallow copy and deep copy?→🟡 MediumWhat are property descriptors and property flags (writable, enumerable, configurable)?→🟢 EasyWhat are getters and setters in JavaScript?→🟢 EasyWhat is the difference between Object.freeze() and Object.seal()?→

Practice this in a timed sprint →

5 free questions, no signup required

âš¡ Start Sprint