Destructuring arrays

Tell us what’s happening:
Describe your issue in detail here.

In the assignment they explain how to destructure the arrays, showing that you can put multiple commas to count the index. But when I do [a,] = [b,] it is wrong. Why would they say to do it and then say it is wrong?

Your code so far


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

Your browser information:

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

Challenge: Use Destructuring Assignment to Assign Variables from Arrays

Link to the challenge:

This doesn’t swap the values of a and b. Only the variable(s) on the left side of an equals sign are updated.

1 Like

In my post I put two commas, and when I submit it only shows one.
But anyways, what you are saying is that when it looks like this:

[a, b] = [b, a]

the arguments on the right are going into the same place on the left? and if I put two commas it doesn’t work for some reason?

What is the version with ‘two commas’? Putting

is very different than

because there are two variables on the left vs one.

Adding extra commas doesn’t change how many variables you have on the left, only where they are in the array you are destructuring.