Use Destructuring Assignment to Assign Variables from Arrays - it worked but why?

Tell us what’s happening:
I actually solved this, but I had to remove ‘const’ from my solution. I thought for this to be considered destructuring I had to use ‘const’ to reassign?

Your code so far


let a = 8, b = 6;
// Only change code below this line

[a, b] = [b, a]

console.log(a, b)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62

Challenge: Use Destructuring Assignment to Assign Variables from Arrays

Link to the challenge:

a and b are already declared with let above, you’re reassigning them via destructuring.

In plain English that line is saying "assign a to the first value of [b, a], and assign b to the second value of [b, a]".

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.