If the value on the right is not an array or object, it will be converted to an object first, but null and undefined cannot be converted to an object.

Uncaught TypeError: Cannot read property ‘a’ of undefined/null

var obj = undefined; Or null const {a=1} = objCopy the code

1.1 How to assign an initial value if the value on the right is null or undefined? (plus | | {})

var obj = null;
const { a = 1 } = obj || {}
Copy the code

2. When objects and arrays are destructively assigned, the default value is valid only if (===) undefined

Let {a = 1} = {a: undefined}; // a: 1 let { a = 1 } = {a: null}; Let [a=1] = [undefined]; // a: 1 let [a=1] = [null]; // a: nullCopy the code