Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active February 4, 2020 12:02
Show Gist options
  • Save gladchinda/6009b54a6cbdbeca47e7830b601960a1 to your computer and use it in GitHub Desktop.
Save gladchinda/6009b54a6cbdbeca47e7830b601960a1 to your computer and use it in GitHub Desktop.
const item = {
quantity: 4,
unitPrice: 49.99,
discount: 0.24,
get price () { return (this.quantity * this.unitPrice * (1 - this.discount)).toFixed(2) }
};
// String concatenation
const pricing = 'The total price of ' + item.quantity + ' units of this item is $' + item.price + '.';
console.log(pricing); // "The total price of 4 units of this item is $151.97."
const item = {
quantity: 4,
unitPrice: 49.99,
discount: 0.24,
get price () { return (this.quantity * this.unitPrice * (1 - this.discount)).toFixed(2) }
};
// String substitution with template literal
const pricing = `The total price of ${item.quantity} units of this item is $${item.price}.`;
console.log(pricing); // "The total price of 4 units of this item is $151.97."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment