Open this example in the interactive library
Source code
const greet = ({ name = "Guest", punctuation = "!" } = {}) =>
`Hello ${name}${punctuation}`;
console.log(greet(), greet({ name: "Ada" }));
Sample output
Hello Guest! Hello Ada!

Use default destructuring. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
const greet = ({ name = "Guest", punctuation = "!" } = {}) =>
`Hello ${name}${punctuation}`;
console.log(greet(), greet({ name: "Ada" }));
Hello Guest! Hello Ada!