JavaScript Classes

JavaScript Classes


JavaScript Classes
In this tutorial, you will learn about JavaScript Classes with the help of the Examples:
Classes are a template for creating objects. They encapsulate data with code to work on that data.
A class is one of the features introduced in the ES6 version of JavaScript.
A class is a blueprint for the object. You can create an object from the class. 
ES6 Class declaration
ES6 introduced a new syntax for declaring a class as shown in this example:
class Person {
         constructor(name) {
             this.name = name;
  }
  getName() {
      return this.name;
  }
Example 1 –
Output -
Example 2 –
Output –