ES6 Assign Arrays from Variables

why does it need to be [a,b]= [b,a] ;
we dont need const bc let was used?
strictmode const vs const not in strictmode?
strictmode only used inside a function?
below is first attempt:

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

Here’s what your code is doing:

let a = 8, b = 6;

Declaring variables and assign values.

(() => {
  "use strict";
  // change code below this line
 const [a,b]= [b,a] ;
  // change code above this line
})();

This is an Immediately Invoked Function Expressions. It means that the code gets executed right away. The variables are inside the function and are scoped to that block which is why there isn’t an error getting thrown.

So your code isn’t really going to do anything. The outside a and b are declared and have been bound to a value but the inside variables have been declared but have no values.

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

Here’s an implementation that gets your code working and gives you an idea of how you can pass parameters into the function.

Hope that helps!