what is a js class constructor code example
Example 1: javascript class constructor
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
const person = new Person("John Doe", 23);
console.log(person.name); // expected output: "John Doe"
Example 2: es6 class example
var Polygon = class {
constructor(height, width) {
this.height = height;
this.width = width;
}
}