Class in JavaScript

In JavaScript class is defined with the constructor.

Class declaration:

class circle{





First declare class otherwise give an reference error, because class is not housing but method is housing.

Reference error:

const p =new Rectangle();

class Rectangle{




class Rectangle {

    constructor(height, width){




get area(){

    return this.calcArea();


calcArea() {

    return this.height * this.width;



const square = new Rectangle(10,10);

const square = new Rectangle(10,10);

Powered  by Codersarts