This is the fourth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

The left and right sides have the same structure

## Array destruct assignment

The value of the right array is deconstructed and assigned to the corresponding value of the left array. This applies to var, let, and const

``````var [v1, v2 ,vn] = [a, b, c];

let [v1, v2, ...v3] = [a, b, c, d, e]; // v3 = [c ,d ,e];

const [v1, v2 ,[v3, ,v4], v5] = [1.2[3.4].5];
Copy the code``````

Note 1: An error will be reported if the item to the right of the equals sign is not an array

Note 2: Assignment is still successful if there are fewer values in the left side of the equals sign than in the back

## 2. Object deconstruction assignment

``````var {fn : fn} = {fn : 'aaa' };

var {fn} = {fn : 'aaa'}; // Find the same key in the right object as in the left.
Copy the code``````

Note: The value on the left is actually assigned,

var{fn : foo} = {foo : ‘aaa’}; The value foo is assigned and fn does not exist after the assignment

``var {p : [x, {y} ] } = {p : ['hello', {y : 'world} ] }; // x='hello' y='world'** nested assignment **Copy the code``
``````var x;

{x} = {x : 1}; // The Error engine interprets {x} as a block of code

({x} = {x : 1});
Copy the code``````

## The default value problem

``````var [a, b, c='暂无'] = ['Stri'.'20',];

console.log(c); // 'No... ';

var [a, b, c='暂无'] = ['Stri'.'20'.null];

console.log(c); // null; Null means that null also represents a value
Copy the code``````

## 4. Parentheses

``````var [(a)] = [1];

var { x: (c) } = {};

var {o : ({p : p }) } = {o: {p :2}};Copy the code``````

These are all examples of errors because they are variable declaration statements and the schema cannot use parentheses

function f( [ (z) ]){return z; } // Error function arguments are also variable declarations and cannot have parentheses

``````({ p : a}) = { p : 42};

([a]) = [5]; // The above code places the entire pattern in parentheses

[({p : a}), { x : c}] = [{}, {} ]; // Place a layer of nested patterns in parentheses
Copy the code``````

Correct: These are assignment statements, and parentheses are not part of the pattern

``````[(b)] = [3]; // The pattern takes the first member of the array, regardless of parentheses

({ p : (d)} = {}); // The mode is p, not d

[(parseInt.prop)] = [3]; / / class 1
Copy the code``````