I understand that, using ES6 syntax, a function can be made that takes an object as a parameter and that parameter can have a default value, like so:
functio
You can use destructuring in parameters to provide default values:
function exampleFunction({val1 = 1, val2 = 2} = {}) {
console.log(val1, val2);
}
exampleFunction({val1: 5});
exampleFunction();
If you want to keep the parameter as an object, you can use Object.assign
:
function exampleFunction(origParams = {}) {
const objParam = Object.assign({ val1: 1, val2: 2 }, origParams);
console.log(objParam.val1, objParam.val2);
}
exampleFunction({val1: 5});
exampleFunction();