ganqqwerty / 123-Essential-JavaScript-Interview-Questions

JavaScript interview Questions
BSD 3-Clause "New" or "Revised" License
5.01k stars 1.18k forks source link

Question 44 (Method No-3) #118

Closed ghost closed 1 month ago

ghost commented 1 month ago

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 .

Screenshot 2024-08-27 at 4 34 45 PM