Hi guys,
I’m a bit confused as to why in a function we would want to perform a console.log then return the value of a variable.
I can understand why we would want to return a value, then console.log it, but not the other way round.
Please can you advise?
I’ve pasted below a block of code from the getters & setters part illustrating this.
Thanks
Sophie
let restaurant = {
_name: ‘Italian Bistro’,
_seatingCapacity: 120,
_hasDineInSpecial: true,
_entrees: [‘Penne alla Bolognese’, ‘Chicken Cacciatore’, ‘Linguine pesto’],
set seatingCapacity(newCapacity) {
if (typeof newCapacity === ‘number’) {
this._seatingCapacity = newCapacity;
} else {
console.log(Change ${newCapacity} to a number.
)
}
},
get seatingCapacity() {
console.log(There are ${this._seatingCapacity} seats at Italian Bistro.
);
return this._seatingCapacity;
}
}
restaurant.seatingCapacity = 150;
const seats = restaurant.seatingCapacity;