I have a javascript function with three default parameters.
function myFunction(first, second='default second variable', third=function(){console.log('default third function')}, forth=function(){console.log('default forth function')}) {
console.log(first);
console.log(second);
third();
forth();
}
myFunction('hello', function(){console.log('next')});
I want to call myFunction
with the first and third parameter, however it seems i can only pass the two arguments for two consecutive parameters and must supply an argument for the first parameter. Hence, the second function argument is printed as-is and is never evaluated as a function.
Questions:
1. How does ECMAScript 2015 (ES6) select arguments for default parameters?
2. Can I specify the first parameter as default where I have multiple parameters?
3. Also, can I assign arguments to non-consecutive parameters?