skip to content

__proto__ vs .prototype

The single most common confusion in JavaScript interviews: `.prototype` is a property that functions carry, while `[[Prototype]]` (exposed as `__proto__`) is the link every object follows during lookup. Knowing which is which, and the modern accessor for each, is table stakes.

part ofJavaScriptoverview, primer and where to startread it →
on this pageshow

questions

5

Starting from the array literal `[]`, which objects does its prototype chain link to, and what terminates the chain?

level: middleimportance: should knowfreq 55%

basics

~10 s

An array links to Array.prototype, which links to Object.prototype, which links to null. Null terminates every ordinary prototype chain, so Object.prototype is the last real object a lookup can reach.

open as a page

Why is `__proto__` considered legacy in JavaScript, and which standard APIs replace reading and writing it?

level: middleimportance: should knowfreq 58%

basics

~10 s

proto is a legacy accessor defined on Object.prototype and standardised only in the web-compatibility annex. Object.getPrototypeOf reads an object's prototype link and Object.setPrototypeOf writes it; both are core-language functions that work on any object.

open as a page

Which of JavaScript's callable forms carry a `.prototype` property — function declarations, arrow functions, object-literal method shorthand, classes, and generator functions?

level: middleimportance: should knowfreq 40%

basics

~10 s

Function declarations and expressions, classes, generator functions and async generator functions have a .prototype property. Arrow functions, method shorthand, async functions and bound functions do not; reading .prototype on them gives undefined.

open as a page

Why is calling `Object.setPrototypeOf` on an already-created object discouraged, and what should you do instead?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Changing an existing object's prototype invalidates the engine's optimised assumptions about that object's shape and the caches at every site that touches it, forcing slower generic lookups. Create objects with the prototype they need instead of retrofitting it.

open as a page