Understanding class Syntax in JavaScript in Javascript


ES6 classes provide a syntactic sugar over JavaScript’s existing prototype-based inheritance.

Source Code

class Person {
  constructor(name) {
    this.name = name;
  }
  greet() {
    console.log(`Hello, ${this.name}`);
  }
}
let person = new Person('John');
person.greet(); // Hello, John
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments