Skip to main content
D
JavaScript
JavaScript Classes

JavaScript Classes

JavaScript classes provide blueprints for creating multiple objects.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript uses classes as templates to create objects that share the same structure. If a developer needs to build 50 different enemies for a game, they build one Enemy class and reuse it 50 times to save effort.

Syntax

Syntax
1/* class syntax */
2class ClassName {
3  constructor() { ... }
4}

Example

Example
1/* this creates a class */
2class Car {
3  constructor(brand) {
4    this.carname = brand;
5  }
6}
7let myCar = new Car("Ford");

Key Points

  • The `class` keyword defines the template.
  • The `constructor()` method runs automatically when creating a new object.
  • The `new` keyword creates an object from the class.
  • Classes act as a cleaner syntax for older prototype patterns.

Up Next

Continue your journey with the next topic.

Go to JS Modules