1 min read

Default Parameters

Default parameters allow you to initialize function parameters with default values if they are not provided when the function is called.

function greet(name = 'Guest') {
  console.log(`Hello, ${name}!`);
}

greet(); // "Hello, Guest!"
greet('John'); // "Hello, John!"