Default Params
Old ES5 way to set default params
// This is what people normally do in ES5 to set default params
function link(height, color, callbackFn) {
var height = height || 50;
var color = color || 'red';
var callbackFn = callbackFn || function() {};
// function content...
}// So there is a better way to do this, it checks param is actually undefined or not:
function link(height, color, callbackFn) {
var height = typeof height !== 'undefined' ? height : 50;
var color = typeof color !== 'undefined' ? color : 'red';
var callbackFn = typeof callbackFn !== 'undefined' ? callbackFn : function() {};
// function content...
}ES6 way to write default params
Last updated
Was this helpful?