Default value while destructuring
suggest changeA missing property, or one whose value is undefined, can be given a default while destructuring. The default is not used for other values, including null, 0, and "". Destructuring a nested pattern from null or undefined still throws TypeError.
const obj = {a : 1};
const {a : x , b : x1 = 10} = obj;
console.log(x, x1); // 1, 10
const arr = [];
const [a = 5, b = 10, c] = arr;
console.log(a, b, c); // 5, 10, undefined
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents