I was adding validation functions for my Node application, and want a custom message for the field I provide in that function. The issue is, some options need to have a default values, and others I can pass as parameters.
let field = 'email';
let options = {
'message': `${field} is required`
}
function validation(field, opt = options) {
console.log(opt.message);
}
validation('password');
validation('confirm', {message: 'Confirm password is required'})
But in this case, the output is
"email is required"
"Confirm password is required"
While I want the output to be
"password is required"
"Confirm password is required"
I also want to know how Javascript works for this code. How it is accessing all the stuff and how to get the required output.
Thanks