Use Destructuring Assignment to Assign Variables from Arrays

Use Destructuring Assignment to Assign Variables from Arrays
0.0 0

#1

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays/


#2

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.