object destructuring with default value code example
Example 1: object destructuring
let a, b, rest;
[a, b] = [10, 20];
console.log(a);
console.log(b);
[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(rest);
Example 2: js object destructuring with defaults
const { dogName = 'snickers' } = { dogName: undefined }
console.log(dogName)
const { dogName = 'snickers' } = { dogName: null }
console.log(dogName)
const { dogName = 'snickers' } = { dogName: false }
console.log(dogName)
const { dogName = 'snickers' } = { dogName: 0 }
console.log(dogName)
Example 3: mdn destructuring
let a, b;
[a, b] = [1, 2];
console.log(a);
console.log(b);
Example 4: object destructuring default value
let a, b;
[a=5, b=7] = [1];
console.log(a);
console.log(b);