ES6 allowed according to a certain pattern, the array and object to extract values, variable assignment, which is referred to deconstructed (Destructuring).
If deconstruction is not successful, the value of the variable is equal undefined
.
let [x, y] = [1, 2, 3]; x // 1 y // 2 let [a, [b], d] = [1, [2, 3], 4]; a // 1 b // 2 d // 4
If the right side of the equal sign is not an array (or strictly speaking, can not traverse the structure, see "Iterator" chapter), it would be an error.
// 报错 let [foo] = 1; let [foo] = false; let [foo] = NaN; let [foo] = undefined; let [foo] = null; let [foo] = {};