Interview Q&A · JavaScript · 12 questions in this topic

Objects & Prototypes — JavaScript Interview Q&A

All JavaScript topics

Prototype-based objects — literals, property mechanics, inheritance chains and classes as sugar. Part of Objects, Prototypes & this · 204 questions in the JavaScript bank.

How do you create and use objects (literals, property access)?

Answer

Literals ({}) with shorthand ({x}), computed keys ({[k]: v}), and methods; access via dot (static known keys) or brackets (dynamic keys, special names). Destructuring unpacks; spread/rest clones and picks.

Brackets-for-dynamic, dot-for-static is the access rule.

Example

Example.jsjs
const k = 'role';
const u = { name: 'Al', [k]: 'admin' };
const { name } = u;          // destructure
const copy = { ...u, active: true }; // spread clone+extend

What is the prototype chain? How does property lookup work?

Answer

Every object links to a prototype (Object.getPrototypeOf); failed own-property lookups walk up the chain to Object.prototype, then undefined. Assignment always writes own properties (never up-chain); methods live on prototypes so instances share them.

Lookup-up, write-own is the two-direction rule.

Example

Example.jsjs
const animal = { speak() { return '...'; } };
const dog = Object.create(animal); // dog.__proto__ === animal
dog.speak(); // found up-chain

💡 Shared-methods-on-prototype is the memory rationale.

How does prototypal inheritance differ from classical inheritance?

Answer

Prototypal: objects inherit directly from objects (live delegation links, mutable at runtime). Classical (Java-style): classes stamp instances from blueprints. JavaScript classes are sugar over constructor-prototype wiring — the chain underneath stays prototypal.

Delegation-links vs blueprints is the paradigm split.

Example

Example.jsjs
class Dog extends Animal { bark() {} } // sugar over:
// Dog.prototype.__proto__ === Animal.prototype

💡 Sugar-over-prototypes explains why instanceof and extends still chain.

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits