Created
October 13, 2014 23:18
-
-
Save flarnie/f4842f959db3749ce570 to your computer and use it in GitHub Desktop.
ES6 Default Function Arguments
This file contains hidden or 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 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