ES6: Use Destructuring Assignment to Assign Variables from Arrays question

I have this code here:

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

My question is, how a and b enter the function?

They are global variables

You need to use destructuring of the global variables, if you use const you are making the variables local, and that doesn’t invert the global ones

1 Like

Thanks for the answer.