I couldn't seem to find this existing topic, but I'm sure it has been thought about thousands of times (I'm seeing stuff online for over a decade).
It would be nice to have some optional/nullish syntax to allow destructuring defaults to include both undefined and null. Currently, we have this which will only populate the default if the value is undefined:
const { myVar = 'default' } = otherVar;
// otherVar = {} has myVar = 'default' for output
// otherVar = { myVar: null } has myVar = null for output
// otherVar = { myVar: 1 } has myVar = 1 for output
However, it would nice to have a syntax to have null || undefined revert to the default. Something like:
const { myVar ?= 'default' } = otherVar;
// otherVar = {} has myVar = 'default' for output
// otherVar = { myVar: null } has myVar ='default' for output
// otherVar = { myVar: 1 } has myVar = 1 for output
A couple potential ways to define this:
const { myVar ?= 'default' } = otherVar;
const { myVar? = 'default' } = otherVar;
const { myVar ?? 'default' } = otherVar;