Favorites

JavaScript class Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
class
JavaScript Functions and ClassesThis statement is supported by all modern browsers.
Updated 28th November 2026

The class declaration defines a blueprint for creating objects, with a constructor, methods, getters, static members and private fields, and can extend another class.

Description

A class declaration creates a class: a template for objects that share the same structure and behavior. The constructor sets up each new instance, methods are shared by all instances through the prototype, and get/set define computed properties. static members belong to the class itself, and names starting with # are truly private, accessible only inside the class.

extends creates a subclass, and super calls the parent's constructor or methods. Class bodies always run in strict mode, classes must be called with new, and unlike function declarations they aren't usable before the line that declares them.

Classes are mostly a cleaner syntax for JavaScript's existing prototype-based inheritance: methods live on ClassName.prototype, and typeof a class is "function". Class fields, written directly in the class body, give each instance its own property and run before the constructor body. A static { } block runs once when the class is defined, which is useful for more complex static set-up. Classes can also be written as expressions, const Model = class { ... }.

Syntax

class Name extends Parent {
  #privateField = value;
  static staticProp = value;
  constructor(params) {
    super(params);
  }
  method() {}
  get prop() {}
}

Example

class Account {
  #balance = 0;
  static count = 0;
  constructor(owner) { this.owner = owner; Account.count++; }
  deposit(amount) { this.#balance += amount; return this; }
  get balance() { return this.#balance; }
}

class Savings extends Account {
  addInterest(rate) { return this.deposit(this.balance * rate); }
}

const acc = new Savings('Sam').deposit(100).addInterest(0.05);
console.log(acc.owner, acc.balance, Account.count);
console.log(acc instanceof Account);

Browser Support

The following information will show you the current browser support for the class statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee