Prototype Chain and Inheritance
What common mistakes do candidates make around Prototype Chain and Inheritance, and how do you avoid them?
Answers use simple, clear English.
Quick interview answer
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.
Detailed answer
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. 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: Fresher.
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