0 votes
in JavaScript by
How do you define instance and non-instance properties in Javascript?

1 Answer

0 votes
by

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;
...