Tell us what’s happening:
Hey guys, I need some help in understanding why const [a, b] = [b, a] does not work but [a, b] = [b, a]works. I apologize if this is a bad question. Any help I can get would be greatly appreciated!
Your code so far
let a = 8, b = 6;
(() => {
“use strict”;
// change code below this line
const [b, a] = [a, b]
// change code above this line
})();
console.log(a); // should be 6
console.log(b); // should be 8
let a = 8, b = 6;
(() => {
"use strict";
// change code below this line
const [a, b] = [b, a]
// 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/69.0.3497.100 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