Tell us what’s happening:
says that we are supposed to, “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.”
But the test to work on offers this starting code:
let a = 8, b = 6;
// Only change code below this line
But that’s not an array. It’s two variables assigned single values!
The given solution says that the answer is:
[ a,b ] = [ b,a ]
I don’t understand how that’s an example of destructuring. It strikes me more as a case of creating a new array from two declared single-value variables and then rearranging the elements. What makes this a test of destructuring?
Your code so far
let a = 8, b = 6; // Only change code below this line console.log(b,a);
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36.
Challenge: Use Destructuring Assignment to Assign Variables from Arrays
Link to the challenge: