Question presented to candidate: "Explain what prototypal inheritance actually is in JavaScript, and how the mechanism works under the hood."
What a strong answer should cover:
- Every JavaScript object has a hidden internal link, the [[Prototype]] slot, pointing to another object (or to null).
- Property lookup walks this link: if a property is not found directly on an object, the engine automatically checks the object's prototype, then that prototype's own prototype, and so on, until it finds the property or reaches null.
- Object.create(proto) is the most direct way to create an object with a chosen prototype, with no constructor function involved at all.
- Ctor.prototype (a plain object property that lives on a function) and instance.proto (the actual internal link on an instance) are two distinct but related things, and mixing them up is a very common source of confusion.
- Because lookup happens live at call time rather than by copying, patching a shared prototype after instances already exist changes the behavior of every existing instance -- inheritance is genuinely dynamic, not a one-time copy.
Clarifying questions expected:
- "Should I also contrast this with classical, class-based inheritance, or focus purely on how the JavaScript mechanism itself works?" (the comparison has its own dedicated question)
Code / implementation expected: Yes -- a runnable snippet showing Object.create-based delegation and a live patch to a shared prototype changing an existing instance's behavior.