Skip to content

Instantly share code, notes, and snippets.

@wklug
Created October 27, 2016 03:45
Show Gist options
  • Save wklug/9c13ebe24d0d25525562a5dd823ec545 to your computer and use it in GitHub Desktop.
Save wklug/9c13ebe24d0d25525562a5dd823ec545 to your computer and use it in GitHub Desktop.
ES6 - Default function parameters
/**
* 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