Default Values for Function Parameters
Let's start by defining the function sendGreeting
that takes two parameters: name
and greeting
. If no parameters are provided, it defaults to Guest
and Hello
.
function sendGreeting(name = 'Guest', greeting = 'Hello') { // Function body will go here }
Next, let's compose and display the greeting message:
function sendGreeting(name = 'Guest', greeting = 'Hello') { // Display the composed message console.log(`${greeting}, ${name}!`); };