๐Ÿงฌ JavaScript

JavaScript Prototypes โ€” What class Actually Does Under the Hood

๐Ÿ“… Jul 4, 2026 โฑ 3 min read

"Explain prototypes" filters senior-track candidates. The mental model is one sentence: when a property isn't on an object, JavaScript looks up a chain of linked objects until it finds it or runs out.

Seeing the chain

const arr = [1, 2, 3];
arr.push(4);
// arr has no "push" โ€” found on Array.prototype
// chain: arr โ†’ Array.prototype โ†’ Object.prototype โ†’ null

arr.toString();   // found two hops up, on Object.prototype... 
// (actually Array.prototype overrides it โ€” closest wins!)

class is prototype sugar

class Student {
  constructor(name) { this.name = name; }
  greet() { return `Hi ${this.name}`; }
}
// is (almost) exactly:
function Student(name) { this.name = name; }
Student.prototype.greet = function () { return `Hi ${this.name}`; };

// greet lives ONCE on the prototype โ€” 1000 students share it (memory win)

The naming confusion, resolved

Interview payoffs: explains why editing Array.prototype is dangerous, how polyfills work, and what hasOwnProperty actually checks.

โ† All Articles