According to MDN, a JavaScript class is a template for creating objects. It encapsulates data with code to work on that data. Classes in JavaScript are built on prototypes, they have an easy syntax to work with. Classes introduced in the ECMAScript 2015 version.
To create a JavaScript Class, we declare a class keyword with a constructor method inside of it. This constructor is invoked when **new**
is called to create a new object. Take a look at the example below:
JavaScript Class.
Notice that UpperCamelCase should be used by convention for ES6 class names, as in **_SpaceShuttle_**
used above.
In JavaScript, if a class has a child it will be called Superclass, and the child will be called Subclass. So the subclass can inherit methods and properties from the superclass. Let’s Create a class named “Model” which will inherit the methods from the “Car” class:
#javascript #es6 #oop #programming #developer