What is the difference between a prototype and a constructor in TypeScript?
These two concepts get confused constantly. They do different things.
24 Apr 2024

These two concepts get confused constantly. They do different things.
Constructor: builds the object
A constructor runs when you create a new instance with new. It sets up the object's own properties — the data that belongs to this specific instance.
class Person {
constructor(name) {
this.name = name;
}
}
const person = new Person('John');
console.log(person.name); // "John"
Each Person instance gets its own name. That's the constructor's job.
Prototype: shares behavior
A prototype is an object that other objects inherit from. Methods defined on the prototype are shared across all instances — they exist once in memory, not once per instance.
class Person {
constructor(name) {
this.name = name;
}
}
Person.prototype.sayHello = function() {
console.log(`Hello, my name is ${this.name}!`);
};
const john = new Person('John');
john.sayHello(); // "Hello, my name is John!"
sayHello lives on Person.prototype, not on john directly. Every Person instance shares the same function. When you call john.sayHello(), JavaScript walks up the prototype chain and finds it.
The key difference
Constructor = sets up instance-specific data (runs once per new).
Prototype = defines shared behavior (exists once, inherited by all instances).
When you write a method inside a class body, JavaScript puts it on the prototype automatically. The class syntax hides the prototype mechanics, but they're still there.
The trade-off
Prototypes save memory — one function shared across thousands of instances. But prototype chain lookups are slightly slower than own-property access. For most applications, this is irrelevant. For performance-critical code with millions of objects, it might matter.
Understanding this distinction matters because JavaScript's object model is prototype-based, not class-based. The class keyword is syntax sugar. Under the hood, it's still prototypes all the way down.
Production-Ready Systems with LLMs and Agents
A live Maven cohort, 5 October to 2 November: eight 90-minute sessions where you build LLM and agent systems that survive real traffic, real cost and real failure. Tuesdays and Thursdays, 7:30 to 9:00pm London.
Cohort 2 starts 5 October. Eight live sessions, $1,500.
View the live cohortKeep reading
- TypeScript Anti-Patterns That Cost You Twice: Build Time, Runtime, and the Interview
- The Frontend Toolchain Is Now Written in Rust and Go. What That Means for You
- oxlint vs ESLint: Why I Replaced ESLint with oxlint
- SystemJS Is Dead. Native ESM Finally Won.
- Replace Axios with a Simple Custom Fetch Wrapper (Production-Ready Guide)
- Stop Shipping ChatGPT Wrappers. Ship an Agent in TypeScript, or Don't Bother.