til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Default Parameters for Functions

For functions in JavaScript you can define a default value for a parameter for handling the case where a parameter is not provided, falling back to the dafault.

const greeting = (title = 'World') => {
    return `Hello, ${ title }!`;
};

console.log(greeting());

module.exports = { greeting }

So when greeting is invoced without any parameters like so: console.log(greeting()); it will emit the interpolated string:

$ node helloworld.js
Hello, World!

Resources and References