Default parameters

 Default parameters


Default parameters allow you to set default values for function parameters. If a value is not provided for a parameter, the default value will be used instead. Here's an example:


function greet(name = 'world') {

  console.log(`Hello, ${name}!`);

}


greet(); // Output: Hello, world!

greet('John'); // Output: Hello, John!

In the code above, the greet function has a default parameter of 'world' for the name parameter. If a value is not provided for name, the default value will be used instead.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...