this
refer to and what is the advantage to using this
?
this
resides, which in this case is dog
. This is useful if you’re using the same code to create multiple objects and don’t want to change the object name inside the code each time.const dog = {
name: 'Spot',
age: 2,
color: 'white with black spots',
humanAge: function (){
console.log(`${this.name} is ${this.age*7} in human years`);
}
}