Destructuring Assignment

Destructuring Assignment
0

#1

Tell us what’s happening:

I already passed the challenge by putting a and b value separate but the question is: Why when I put [a, b] = [6, 8]; does not work?

Your code so far


let a = 8, b = 6;
(() => {
  "use strict";
  // change code below this line
  [a] = [6];
  [b] = [8];
  // 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 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

Because the tests are expecting you to use the a and b variables in the destructuring. What you have written is the same as writing:

a = 6;
b = 8;

This defeats the entire purpose of use destructuring.


#3

actually I think you need to swap the value of a and b insted of just assign new values to them.