ES6/ES2015 object destructuring and changing target variable

You can assign new variable names, like shown in this MDN Example

var o = { p: 42, q: true };

// Assign new variable names
var { p: foo, q: bar } = o;

console.log(foo); // 42
console.log(bar); // true  

So, in your case, the code will be like this

const b = 6;
const test = { a: 1, b: 2 };
let { a, b: c } = test;
console.log(a, b, c); // 1 6 2

Online Babel Demo

Leave a Comment