Explain the difference between classical inheritance and prototypal inheritance in JavaScript.

Instruction: Describe the two inheritance models and discuss how JavaScript implements prototypal inheritance.

Context: This question evaluates the candidate's understanding of JavaScript's object model and its differences from classical inheritance paradigms.

Official answer available

Preview the opening of the answer, then unlock the full walkthrough.

Classical Inheritance: Traditionally, in languages like Java or C++, inheritance is classical. This means it follows a class-based paradigm where you define blueprints (classes) for objects. A class can inherit properties and methods from another class, forming a hierarchy. This model is strict, enforcing a one-way, top-down, parent-child relationship structure that's familiar to most developers. It's straightforward in concept but can become complex and rigid, especially in deep inheritance chains.

In contrast,...

Related Questions