
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>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
//JavaScript class
class Name {
constructor(myName) {
this.name = myName;
}
present() {
return "My Name Is " + this.name;
}
}
myName = new Name("Farhan Sakib Jesy");
console.log( myName.present());
</script>
</body>
</html>
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.