Use Destructuring Assignment to Assign Variables from Arrays

Tell us what’s happening:

Your code so far

let a = 8, b = 6;
((a,b) => {
  "use strict";
  // change code below this line
  [b,a] = [a,b];
  // change code above this line
console.log(a); // should be 6
console.log(b); // should be 8

Your browser information:

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

Link to the challenge:

This line’s the problem. You’re declaring new a and b variables inside the arrow function, and these are what’s getting swapped, not the a and b at the beginning.

1 Like