Prototypes & the Chain in JavaScript
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.
Lookup walks upward
Missing locally? Check the prototype, then its prototype, to null — shared methods resolve through the chain.
Constructors assign prototypes
Instances of Dog delegate to Dog.prototype — methods defined once, available to all.
Object.create chooses
Object.create(proto) builds with an explicit prototype — delegation without constructors or classes.
Own vs inherited
hasOwnProperty filters inherited keys — for...in and spread traverse differently, know which you need.
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"));Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.