Last active
March 3, 2019 18:11
-
-
Save BolajiAyodeji/815d80d4b44dcc177ac39458989800d8 to your computer and use it in GitHub Desktop.
Default parameters in functions
This file contains 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 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