Created
October 27, 2016 03:45
-
-
Save wklug/9c13ebe24d0d25525562a5dd823ec545 to your computer and use it in GitHub Desktop.
ES6 - Default function parameters
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
/** | |
* ES6 - Default function parameters. | |
* | |
* Define default value for empty function parameters. | |
**/ | |
function sayHello(name, isPirate = false) { | |
if (isPirate) { | |
console.log(name + ' says: Arrr! This be good grog!'); // Manny Bones says: Arrr! This be good grog! | |
} else { | |
console.log(name + ' says: Hi, how are you?'); // P. Nutt says: Hi, how are you? | |
} | |
} | |
sayHello('Manny Bones', true); | |
sayHello('P. Nutt'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment