Skip to content

Instantly share code, notes, and snippets.

@sarahquigley
Created May 2, 2018 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarahquigley/b7e4d1c4c4ec49009a1ecdfa22ecc6d7 to your computer and use it in GitHub Desktop.
Save sarahquigley/b7e4d1c4c4ec49009a1ecdfa22ecc6d7 to your computer and use it in GitHub Desktop.
Example of ES6 Default Function Parameters
/* ES5 */
function dogExplainsCats (behaviour, reason) {
if (reason === undefined) {
reason = 'evil';
}
return 'Why cats ' + behaviour + '? Because cats ' + reason + '.';
}
dogExplainsCats('poke you in face when sleeping');
// > 'Why cats poke you in face when sleeping? Because cats evil.'
/* >= ES6 */
function dogExplainsCats (behaviour, reason = 'evil') {
return `Why cats #{behaviour}? Because cats #{reason}!`;
}
dogExplainsCats('poke you in face when sleeping');
// > 'Why cats poke you in face when sleeping? Because cats evil.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment