Q: Assign default value by object destructuring to object's properties Is it somehow possible to destructure an object, set a default value, and assign this default value directly to the object's property?
Consider this code


let foo = {};
let {bar = 1} = foo;
console.log(foo); // {}
console.log(bar); // 1


As you can see, foo still doesn't have a bar property. Is there something like below possible, to assign the prop and default value directly to the object:
let {bar = 1: foo.bar}

This is obvious illegal syntax. 
Is there any one liner I can use to get foo to be
{bar: 1}

after the destructuring is done?

A: You could take the object with property as target by using the object property assignment pattern [YDKJS: ES6 & Beyond].


var foo = {};

({ bar: foo.bar = 1 } = foo);
console.log(foo);

foo.bar = 42;
({ bar: foo.bar = 1 } = foo);
console.log(foo);


