typescript destructuring default value code example
Example 1: typescript object destructuring
interface Person {
name: string;
age: string;
}
const { name, age }: Person = obj;
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: object destructuring default value
let a, b;
[a=5, b=7] = [1];
console.log(a);
console.log(b);