Default value while destructuring

suggest change

A 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents