JavaScript Classes

1/22/2020 6:03:06 AM

In the ECMAScript-2015 introduce the class in the latest JavaScript version which known as ECMAScript. In the JavaScript class like object which is user or programmer define object. JavaScript allow to every class contain there won constructors. Other programming language like C# or Java follow the constructor name and class name are same but JavaScript follow the constructor name allows ‘constructor’. We know ‘constructor’ allows call the first. We can pass the paramitas from the JavaScript constructor like other programming language. Also, we can create object of the class then access under the class method or properties. Now given bellow the JavaScript class example code and explain the code:

<!DOCTYPE html>
<script type="text/javascript">
 //JavaScript class 
class Name {
  constructor(myName) { = myName;
  present() {
    return "My Name Is " +;
myName = new Name("Farhan Sakib Jesy");
console.log( myName.present());

In this code we first create a class name as “Name”. This name class contain a constructor. This constructor is receiving a parameter then this parameter value attaches the name variable also the class contain the ‘present’ function. This function responsible to return the full attach value. Now call the function by creating object of the class.