Lesson 27 of 50

Classes in JavaScript

Classes provide a blueprint for creating objects. They simplify object creation and inheritance.

class Animal {
  constructor(type){ this.type = type; }
  speak(){ console.log(this.type + " speaks"); }
}
let dog = new Animal("Dog");
dog.speak();
← Previous Next →