Sometimes you want a parameter to have a sensible value if the caller doesn't provide one. You can give it a default value with =:
function greet(name = "friend", emoji = "👋") {
return `Hello, ${name}! ${emoji}`;
}
console.log(greet("Kenji", "🎉"));
console.log(greet("Chloe"));
console.log(greet());
It prints
Hello, Kenji! 🎉 Hello, Chloe! 👋 Hello, friend! 👋
If an argument is missing (or is undefined), the default is used instead. No more "Hello, undefined!"