ES6 deconstructing task problem

I am running into a problem of failing to understand what the task wants of me.

Use destructuring assignment to swap the values of a and b so that a receives the value stored in b , and b receives the value stored in a .

This is the code provided:

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

As far I can tell a and b are primitive data type and I might be wrong but there is nothing to deconstruct in them? Then I see that one of the last condition of passing the task is:

You should use array destructuring to swap a and b .

So since no array is provided I create one, and I would think that I deconstruction it to reassign values, but the test thinks otherwise.
Can someone make sense of this?

Your code so far


let a = 8, b = 6;
// Only change code below this line
let arr = [];
arr.push(a);
arr.push(b);
const [i, j] = arr;
a = j;
b = i;

Your browser information:

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

Challenge: Use Destructuring Assignment to Assign Variables from Arrays

Link to the challenge:

You are very very close, however the challenge wants to see that you use destructuring with a and b.

So, it’s expected to see an array, but it’s expected from you to desctructure the array in a and b

Or in other word it’s expected to see something like

let a = 8, b = 6;
[a,b] = <<something to figure out>>

Thank you for your reply. The solution for me was super unintuitive :smiley:

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

This had me LoL when it finaly hit me. I was looking at your hint and thinking: he is referring to a non existing array, this still makes no sense.
1 line of code instead of 6 that I did, humbling experience :smiley:

Thank you Marmiz

it worked when i did [a,b] = [b,a]

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Ok Sorry im new to this thanks for letting me know!

how does it differ from what I posted above???