Skip to content

Instantly share code, notes, and snippets.

@flarnie
Created October 13, 2014 23:18
Show Gist options
  • Save flarnie/f4842f959db3749ce570 to your computer and use it in GitHub Desktop.
Save flarnie/f4842f959db3749ce570 to your computer and use it in GitHub Desktop.
ES6 Default Function Arguments
// ES6 Default Function Arguments
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters
function sayHi(target = 'everyone') {
console.log('Hi ', target, '!');
}
sayHi('Alice'); // Hi Alice!
sayHi(); // Hi everyone!
// ES5 compatible syntax transpiled by es6-transpiler
// https://github.com/termi/es6-transpiler
var sayHi = function() {
var target = arguments[0];
if(target === void 0) target = 'everyone';
console.log('Hi ', target, '!');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment