Skip to content

Instantly share code, notes, and snippets.

@aderaaij
Last active November 12, 2017 15:14
Show Gist options
  • Save aderaaij/783ffaf1c88118b101199ec08c258026 to your computer and use it in GitHub Desktop.
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.
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