Reputation: 1764
What happens when the brackets are left off on the LHS
(Left Hand Side) when using the destructuring assignment syntax? For example:
{
let a,b = [1,2];
console.log(a, b);
}
{
let [a,b] = [1,2];
console.log(a, b);
}
If brackets are not included, does it act equivalent to doing:
let a=undefined, b=[1,2];
Or what exactly occurs when brackets are left off?
Upvotes: 0
Views: 61
Reputation: 2556
When the brackets are left off on the LHS (Left Hand Side), it would become a variable assignment as you can declare multiple variables separated by a comma.
So:
let a,b = [1,2];
Is equivalent to:
let a;
let b = [1,2];
console.log(a); // undefined
console.log(b); // [1, 2]
Upvotes: 1
Reputation: 27245
You can declare multiple variables with a single let
by separating them with a comma. So without the brackets you're effectively doing:
let a;
let b = [1, 2];
Upvotes: 2