Prototype Chain and Inheritance
What are the key trade-offs of Prototype Chain and Inheritance? When would you choose it vs alternatives?
Answers use simple, clear English.
Audio N/AQuick interview answer
Pros: Flexible delegation; memory-efficient shared methods on prototype. Cons: Prototype pollution if __proto__ mishandled; instanceof checks break across realms.
Detailed answer
Pros: Flexible delegation; memory-efficient shared methods on prototype. Cons: Prototype pollution if __proto__ mishandled; instanceof checks break across realms. Decision: pick when benefits outweigh operational cost. Core: Objects delegate property lookup via [[Prototype]]. Constructor.prototype is shared by instances. class is syntactic sugar over prototypes; methods live on prototype. Real-time example: Array instances inherit push/pop from Array.prototype; custom types extend via Object.create or class extends. Pros: Flexible delegation; memory-efficient shared methods on prototype. Cons: Prototype pollution if __proto__ mishandled; instanceof checks break across realms. Common mistakes: Confusing __proto__ with prototype property on functions; shadowing constructor incorrectly. Best practices: Prefer class extends for readability; use Object.hasOwn for own props vs inherited. Audience level: Tech Lead.
Full explanation
Objects delegate property lookup via [[Prototype]]. Constructor.prototype is shared by instances. class is syntactic sugar over prototypes; methods live on prototype.
Real example & use case
Array instances inherit push/pop from Array.prototype; custom types extend via Object.create or class extends.
Pros & cons
Pros: Flexible delegation; memory-efficient shared methods on prototype. Cons: Prototype pollution if __proto__ mishandled; instanceof checks break across realms.
Common mistakes
Confusing __proto__ with prototype property on functions; shadowing constructor incorrectly.
Best practices
Prefer class extends for readability; use Object.hasOwn for own props vs inherited.
Follow-up questions
Open one as its own read / solve / listen card