DeveloperBreeze

Javascript Classes Development Tutorials, Guides & Insights

Unlock 1+ expert-curated javascript classes tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your javascript classes skills on DeveloperBreeze.

Understanding JavaScript Classes

Tutorial September 02, 2024
javascript

class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  greet() {
    console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
  }
}

const john = new Person('John', 30);
john.greet(); // Output: Hello, my name is John and I am 30 years old.

The constructor method is a special method that is automatically called when an instance of the class is created. It's typically used to initialize properties of the class.