Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Default Parameters Through Destructuring (ES2015)
// Clear the console on each refresh
console.log('\033c');
function addToCart(product, price, { quantity = 1, currency = 'USD' }) {
console.log(product, price, quantity, currency);
}
let Bicycle = {
product: 'Bicycle',
price: 99.99
}
let Helmet = {
product: 'Helmet',
price: 33.33
}
let Bell = {
product: 'Bell',
price: 11.11
}
Array(Bicycle, Helmet, Bell).forEach(product => {
addToCart(product.product, product.price, { currency: 'CAD' });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment