Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Created January 25, 2016 19:22
Show Gist options
  • Save kopasetik/9f3e7eb61d4942b7e492 to your computer and use it in GitHub Desktop.
Save kopasetik/9f3e7eb61d4942b7e492 to your computer and use it in GitHub Desktop.
Javascript destructuring with default values
// destructuring and default values
const give_discount = ({item, price, percent_discount=10})=>{
console.log('For the ' + item + ' listed at $' + price +
', you get ' + percent_discount + '% off!')
}
give_discount({item: 'sweater', price: 200, percent_discount: 25})
//=> For the sweater listed at $200, you get 25% off!
give_discount({item: 'dress shoes', price: 350})
//=> For the dress shoes listed at $350, you get 10% off!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment