Created
January 25, 2016 19:22
-
-
Save kopasetik/9f3e7eb61d4942b7e492 to your computer and use it in GitHub Desktop.
Javascript destructuring with default values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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