When ES6
support is available, you have the option to utilize destructuring and default parameters, which are handled by the JS engine in an abstracted way.
function validate( {
value = ''
} = {}) {
// The default parameters are specified within the function signature
// This helps maintain a clean function body without needing to add extra code for default values
console.log('value: ' + value );
}
validate({ value: 100 }); // value: 100
validate({ value: 0 }); // value: 0
validate(); // value:
In this example, two patterns are being demonstrated
{
value = ''
} = {}
The value following the equals sign represents the default value expected for the object, while the nested curly braces denote the destructuring pattern being applied.