Reputation: 39
so i dont understand the logic behind "is" keyword (here "isSleeping") i see lots of time studying javascript.
does it mean something results boolean?
let animal = {
walk() {
if (!this.isSleeping) {
alert(`I walk`);
}
},
sleep() {
this.isSleeping = true;
}
};
let rabbit = {
name: "White Rabbit",
__proto__: animal
};
// modifies rabbit.isSleeping
rabbit.sleep();
alert(rabbit.isSleeping);
alert(animal.isSleeping);
Upvotes: 2
Views: 1360
Reputation: 878
"is" is not a keyword it's a way of naming your boolean variables AKA naming convention, so when other people see a variable with "is" in front they know that variable is a boolean.
By @ironmouse The same goes with "has": For example there could be functions like "hasSiblings" or "isMarried" that return a boolean type. However the return type is not set in stone but it is a good convention for developers.
Upvotes: 4