Last active
November 12, 2017 15:14
-
-
Save aderaaij/783ffaf1c88118b101199ec08c258026 to your computer and use it in GitHub Desktop.
An example of how to add default arguments to a named function in es6.
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
function calculateBill(total, tax = 0.10, tip = 0.15) { | |
return total + (total * tax) + (total * tip); | |
} | |
console.log(calculateBill(100)); | |
// Calculate bill with custom tip value and default tax value. Pass undefined | |
// expliclitely to use a default value that's not the first or last function argument | |
const bill = caluculateBill(100, undefined, 0.20); | |
console.log(bill); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment