FrontendDeveloper.in

JavaScript question detail

How do you define instance and non-instance properties

The Instance properties must be defined inside of class methods. For example, name and age properties defined inside constructor as below,

class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}

But Static(class) and prototype data properties must be defined outside of the ClassBody declaration. Let's assign the age value for Person class as below,

Person.staticAge = 30;
Person.prototype.prototypeAge = 40;
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399