Ask Your Question
1

Can I assign a variable within destructuring assignment using 'let' and then reassign it later?

asked 2021-12-14 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-05-02 14:00:00 +0000

woof gravatar image

Yes, you can assign a variable within destructuring assignment using 'let' and then reassign it later. Here's an example:

let {a, b} = {a: 1, b: 2};
console.log(a); // output: 1
console.log(b); // output: 2

a = 3;
console.log(a); // output: 3

In this example, we are destructuring an object to assign the values of its properties to variables 'a' and 'b'. We then reassign the value of 'a' to 3, and log it to the console to confirm the change.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-12-14 11:00:00 +0000

Seen: 11 times

Last updated: May 02 '21