I'm curious to understand why the 'constructor called' message is only displayed once instead of five times in this JavaScript example.
const Dog = function(name, age){
this.name = name;
this.age = age;
console.log('constructor called');
}
const obj = {
dog: new Dog('roofus', 20)
}
const main = ()=>{
for(let i = 0; i < 5; i++){
console.log(obj.dog)
}
}
main();
'constructor called'
Dog { name: 'roofus', age: 20 }
Dog { name: 'roofus', age: 20 }
Dog { name: 'roofus', age: 20 }
Dog { name: 'roofus', age: 20 }
Dog { name: 'roofus', age: 20 }