How to destructure option argument with all default values in ES6?

Yes, you just have to provide a default value for the complete argument:

function myFunction({option1 = true, option2 = 'whatever'} = {}) {
//                                                         ^^^^
    console.log(option1, option2);
    // do something...
}

Leave a Comment