Lesson 6 of 80
How objects inherit in JavaScript — a chain of delegation that class quietly sits on top of.
16 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
When you call `[1,2,3].map(...)`, where does the `map` method actually live?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Every JavaScript object has a hidden link to another object called its prototype. When you ask for a property the object doesn't have, JavaScript follows that link and checks the prototype — and its prototype — until it finds the property or hits the end.
That walk is the prototype chain. It isn't copying; it's delegation — "I don't have it, ask the next one up."
Array methods aren't on your array — they live one link up:
const list = [1, 2, 3];
list.map; // found on Array.prototype, not on `list` itself
list.hasOwnProperty("0"); // found further up, on Object.prototype
And class is sugar over exactly this:
class Animal { speak() { return "..."; } }
class Dog extends Animal { speak() { return "woof"; } }
// Dog.prototype's link points to Animal.prototype — that link is the chain.
You call [1,2,3].map(...). JavaScript looks on the array itself first.
null. Object.prototype's prototype is null — which is why unknown lookups eventually return undefined.class didn't replace prototypes — it's a cleaner way to write them. Understand one and you understand the other."How does inheritance work in JavaScript?" wants the word prototype, not class. If you can say objects delegate up a chain and class is sugar over it, you've answered the real question.