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

PhilipGarnero :

Example :

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

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

kind user :

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;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ES6 destructuring object, default value on assignment when not used as a function parameter?

How to use ES6 destructuring assignment to assign one object to another

Destructuring assignment vs object property access in ES6

Nested in object array destructuring with assignment

Reassign variables using ES6 destructuring assignment syntax

ES6 Destructuring assignment with `this`

When using object destructuring assignment, why is a property "name" cast to string?

TypeScript type modification when using defaults and object destructuring assignment

How to use destructuring assignment to define enumerations in ES6?

How to use array destructuring and assign to an object property in JavaScript ES6

How to override object destructuring for ES class just like array destructuring

Simplify javascript object creation using ES6 destructuring

Create an object from function inputs using ES6 destructuring

destructuring assignment of array stored in object property

Array destructuring into object assignment in a single instruction

What's the difference between object destructuring and normal object assignment in Javascript ES6?

Partial object copying using Destructuring Assignment

ES6 destructuring, dynamic assignment

How to flatten nested array of object using es6

Ugly destructuring when using conditional assignment

How to use a destructuring assignment inside an object

How to use es6 to let or const within if statement

Decypher ES6 const destructuring declaration

Using a destructuring assignment to iterate over an es6 map with nodejs 4.1.2

Object property assignment with destructuring?

Destructuring assignment in object creation

Haskell Tuple destructuring on infinite lists behaves differently when destructuring the Tuple as an argument than when destructuring using let

How to extract nested object property using array destructuring?

How can I add array values to an object using destructuring?