Use-destructuring-assignment-to-assign-variables-from-arrays

I believe the code at top is already in the scope for the function to read (Global Scope)

let a =8,b=6;

so I think re-stating the code below within the function would then make the constant variables only readable within the function. Outside the function, only the global scope of ‘let’ is readable.

const [a,b]
1 Like

const keyword declares block level variables, the statement does not affect global variables.

1 Like

As i read the posts on this article , i found that most of friends are using const to set a variable.
The soloution is het

You have to use :
[a,b] = [b,a]
Instead of :
const [a,b] = [b,a]
or
Let [a,b] = [b,a]
.

The right code is :
let a = 8, b = 6;
(() => {
“use strict”;
// change code below this line
[a,b] = [b,a];
// change code above this line
})();
console.log(a); // should be 6
console.log(b); // should be 8

1 Like