Advertisement
Beginner JavaScript, Classes & Class Syntax

What is a class in JavaScript, and is it a new kind of object model?

Short answer

A class is syntactic sugar over JavaScript's existing prototype-based inheritance. It doesn't add a new object model — under the hood, methods still live on the prototype object, just written with cleaner syntax.

Save JavaScript mock interview
Advertisement
AModel answer
A class is syntactic sugar over JavaScript's existing prototype-based inheritance. It doesn't add a new object model — under the hood, methods still live on the prototype object, just written with cleaner syntax.
class Animal {
  constructor(name) { this.name = name; }
  speak() { return `${this.name} makes a sound.`; }
}
const a = new Animal('Rex');
console.log(a.speak());
Real-world example
Modeling domain entities like User, Order, or Product with clear, readable structure.
Likely follow-ups
  • Is a class hoisted the same way a function declaration is?
Related topics