I am just starting to write in ES6 after years of rigidity sticking to plain ole JS (ES5). One feature that I really like is Object Destructuring while declaring and assigning variables :
function someFunction() {
return Promise.resolve({
a: 0,
b: 1
});
}
let {a, b} = await someFunction();
But there is a particular case where I'd love to transform existing variables like this :
function otherFunction(a, b) {
return Promise.resolve({
a: a + 1,
b: b + 2
});
}
let {a, b} = await someFunction();
{a, b} = await otherFunction(a, b);
Since the two variables were already declared using let
I can't redeclare them. If I switch back to using var
instead of let, I can do that :
var {a, b} = await someFunction();
var {a, b} = await otherFunction(a, b);
Which works perfectly fine but I want to benefit from the strictness of ES6 and the let
keyword, is there a way to destructure-assign without declaring ?