Open this example in the interactive library
Source code
const cart = {
quantity: 3,
price: 4,
get total() {
return this.quantity * this.price;
},
};
console.log(cart.total);
Sample output
12

Open this example in the interactive library
const cart = {
quantity: 3,
price: 4,
get total() {
return this.quantity * this.price;
},
};
console.log(cart.total);
12