If you're using defaults extensively, this seems much more readable:
function usageExemple(a,b,c,d){
//defaults
a=defaultValue(a,1);
b=defaultValue(b,2);
c=defaultValue(c,4);
d=defaultValue(d,8);
var x = a+b+c+d;
return x;
}
Just declare this function on the global escope.
function defaultValue(variable,defaultValue){
return(typeof variable!=='undefined')?(variable):(defaultValue);
}
Usage pattern fruit = defaultValue(fruit,'Apple');
*PS you can rename the defaultValue
function to a short name, just don't use default
it's a reserved word in javascript.