Learn JavaScript
❯ objects.prototypes

Prototypes & the Chain in JavaScript

$concept

Every object links to a prototype it inherits from: property lookup walks the object, then its prototype, upward to Object.prototype (then null). Constructor functions assign shared methods via Dog.prototype.bark (one function for all instances); Object.create(proto) builds objects with chosen prototypes directly; class syntax sugars the same machinery.

Mutating shared prototypes affects every instance (powerful, dangerous), hasOwnProperty distinguishes own from inherited keys, and getPrototypeOf inspects chains. Prototypes explain classes, instanceof, and half of JavaScript's object behavior.

$how it works
1

Lookup walks upward

Missing locally? Check the prototype, then its prototype, to null — shared methods resolve through the chain.

2

Constructors assign prototypes

Instances of Dog delegate to Dog.prototype — methods defined once, available to all.

3

Object.create chooses

Object.create(proto) builds with an explicit prototype — delegation without constructors or classes.

4

Own vs inherited

hasOwnProperty filters inherited keys — for...in and spread traverse differently, know which you need.

$example
function Dog(name) {
this.name = name;
}
Dog.prototype.bark = function () {
return this.name + " woofs";
};
let d = new Dog("Rex");
console.log(d.bark());
console.log(d.hasOwnProperty("bark"));
Output
Rex woofs
false
1bark lives once on Dog.prototype, not on each instance.
2d.bark() resolves up the chain and runs with this bound to d.
3hasOwnProperty reports false — bark is inherited, proving delegation over copying.
$use cases
Reading class behavior as prototype delegation underneath
Shared methods via prototype instead of per-instance copies
Object.create for delegation without constructor machinery
Distinguishing own vs inherited keys in serialization and loops

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.