ES6 Everyday: Default Parameter Values

Our first one’s pretty self-explanatory: with ES6, you can now provide default values for function parameters:

function getWelcomeMessage(name, greeting="Hello") {
  return greeting + " " + name + "! Welcome to the app!";
}

console.log(getWelcomeMessage("Logan"));
// Hello Logan! Welcome to the app!

console.log(getWelcomeMessage("Gordon", "Good evening"));
// Good evening Gordon! Welcome to the app!

Try it out for yourself in this ES6 Fiddle.

Resources