×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

JavaScript Classes



Javascript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over javascript's existing prototype-based inheritance.

A class is a type of function, but instead of using the keyword function to initiate it, we use the keyword class, and the properties are assigned inside a constructor() method

The class syntax contains two components:

Class declarations

Class expressions

<script>

class Element

{

constructor(id,name)

{

this.id=id;

this.name=name;

}

detail()

{

document.write(this.id+" "+this.name+"<br/>")

}

}

var x=new Element(401,"Parveen");

var y=new Element(302,"Deepak");

x.detail();

y.detail();

</script>









JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute