Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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