What is a JavaScript Class?

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.

Image for post

Create a JavaScript Class:

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.

JavaScript Class.

Notice that UpperCamelCase should be used by convention for ES6 class names, as in **_SpaceShuttle_** used above.

Class Inheritance

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:

Class Inheritance.

#javascript #es6 #oop #programming #developer

Understand JavaScript Classes with Practical Examples
7.35 GEEK