Objects can inherit properties and methods from their prototypes through a process called the prototype chain. The prototype chain is a series of linked objects that are used for property and method lookup. When you try to access a property on an object, JavaScript first checks if the property exists on the object itself. If not, it looks at the object's prototype a the object referenced by its [[Prototype]] property. This process continues up the chain until the property is found or until the chain reaches the global Object.prototype object, which is the ultimate ancestor of all objects.
You have let car = { wheels: 4 }; car.__proto__ = { drive() { return 'vroom'; } }; what does car.drive()` return and why?
If you define function Person(){} and then set Person.prototype.age = 30;, what happens when you do new Person().age? Walk me through the lookup.
Suppose you delete a property that exists only on an object's prototype. What will a subsequent access to that property on the instance return?
Your team added a method to Array.prototype and now some pages crash with ‘undefined is not a function’ when calling arr.map. How would you investigate whether prototype pollution is the cause?
A bug shows obj.foo as undefined even though you see foo defined on a parent object. What could be wrong with the prototype chain and how would you debug it?
We refactored a class hierarchy to ES6 class syntax, but an inherited method disappeared. Explain how the prototype chain might have changed and how to restore the behavior.
Our UI library uses a base component prototype that many widgets inherit from, and we’re seeing higher memory usage and slower property access. How would you assess the trade‑offs of prototype inheritance versus composition or class fields?
We need a plugin system where plugins can extend core objects at runtime. Design a prototype‑based extension strategy that is safe for existing code and describe the safeguards you’d put in place.
During a performance audit, deep prototype chains are causing latency in hot loops. What techniques would you use to flatten or cache lookups, and what risks do those techniques carry?
Our legacy codebase heavily mutates prototypes, and we’re migrating to a strict TypeScript codebase with classes. Outline a migration plan that preserves behavior, handles prototype differences, and minimizes cross‑team risk.
We’re building a shared data model that must expose a stable API yet allow per‑team extensions. How would you structure the prototype chain—or choose an alternative pattern—to balance extensibility, type safety, and versioning?
Discuss the long‑term maintenance implications of exposing prototype augmentation in a library used by many downstream services, and propose policies or tooling to manage it safely.