Skip to content

Latest commit

 

History

History
24 lines (16 loc) · 695 Bytes

function_default_parameters.md

File metadata and controls

24 lines (16 loc) · 695 Bytes

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