How to mix const and let when using object or array destructuring assignment in ES6?

PhilipGarnero picture PhilipGarnero · Nov 13, 2017 · Viewed 7.8k times · Source

Example :

const foo = {a: "A", b: "B"}
const {a, b} = foo

What if I want b to be a variable using let ?

Answer

kind user picture kind user · Nov 13, 2017

It seems like you can't differentiate variable's declaration in a one line. However, you could split it into two lines and use a different variable declaration, depends on which variable you want to get.

const { a } = foo; 
let { b } = foo;