0Pricing
JavaScript Academy · Lesson

Class Syntax (Preview): constructor, methods, static, extends

A gentle look at class syntax: constructor, instance methods, static helpers, and simple inheritance with extends.

Intro to class syntax

Goal: See how class syntax maps to prototypes.

  • constructor for setup
  • methods on the prototype
  • static helpers on the class
  • extends for simple inheritance
Class Syntax (Preview): constructor, methods, static, extends — illustration 1

Constructor + method

The constructor runs on new. Methods in the class body are shared by all instances (prototype).

// Class with a constructor and an instance method
class Counter {
  constructor(start = 0) {
    // Initialize fields
    this.value = start;
  }

  // Instance method (lives on the prototype)
  inc() {
    this.value = this.value + 1;
    console.log("Now:", this.value);
  }
}

const c = new Counter(1);
c.inc();
c.inc();
Class Syntax (Preview): constructor, methods, static, extends — illustration 2

All lessons in this course

  1. Prototype Chain & Own-Property Basics
  2. Class Syntax (Preview): constructor, methods, static, extends
← Back to JavaScript Academy