function sendEmail(configuration, provider = "Gmail") {
// Set default value if user has not passed value for provider
// Value of provider can be accessed directly
console.log(Provider: ${provider});
}
// In this call we are not passing provider parameter value
sentEmail({
from: 'xyz@gmail.com',
subject: 'Test Email'
});
// Here we are passing Yahoo Mail as a provider value
sentEmail({
from: 'xyz@gmail.com',
subject: 'Test Email'
}, 'Yahoo Mail');
When i run this code then javascript will throw an error like ReferenceError: sentEmail is not defined.
Solution=> you have to change from sentEmail to sendEmail .
Method 3: Setting default parameter value in ES6
function sendEmail(configuration, provider = "Gmail") { // Set default value if user has not passed value for provider
// Value of provider can be accessed directly console.log(
Provider: ${provider}
); }// In this call we are not passing provider parameter value sentEmail({ from: 'xyz@gmail.com', subject: 'Test Email' }); // Here we are passing Yahoo Mail as a provider value sentEmail({ from: 'xyz@gmail.com', subject: 'Test Email' }, 'Yahoo Mail');
When i run this code then javascript will throw an error like ReferenceError: sentEmail is not defined. Solution=> you have to change from sentEmail to sendEmail .