Destructuring nullable objects Destructuring nullable objects typescript typescript

Destructuring nullable objects


You can use an empty object as fallback, and if D is null or undefined the assigned variables will be undefined.

const D = null;const { a, b, c } = D || {};console.log(a, b, c);