Skip to content

Instantly share code, notes, and snippets.

@BolajiAyodeji
Last active March 3, 2019 18:11
Show Gist options
  • Save BolajiAyodeji/815d80d4b44dcc177ac39458989800d8 to your computer and use it in GitHub Desktop.
Save BolajiAyodeji/815d80d4b44dcc177ac39458989800d8 to your computer and use it in GitHub Desktop.
Default parameters in functions
function interest(principal, rate, years) {
rate = rate || 3.5;
years = years || 5;
return (principal * rate) / 100 * (years)
}
console.log(interest(10000));
//ES6
function interest(principal, rate = 3.5, years = 5) {
return (principal * rate) / 100 * (years)
}
console.log(interest(10000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment