Why the end line can not log 0?


#1

Hi to everyone :slight_smile:
i want to know why the end line log 1 not 0?
i think it will log 0 .
anyone can explain it ?thank you

class Animal {
constructor(name) {
this._name = name;
this._behavior = 0;
}

get name() {
return this._name;
}

get behavior() {
return this._behavior;
}

incrementBehavior() {
this._behavior++;
}
}
class Cat extends Animal {
constructor(name, usesLitter) {
super(name);
this._usesLitter = usesLitter;
}
}

const bryceCat = new Cat(‘Bryce’, false);

bryceCat.incrementBehavior(); // Call .incrementBehavior() on Cat instance
console.log(bryceCat.behavior); // Log value saved to behavior


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.