How can I combine destructuring assignment and optional chaining?
Use short circuit evaluation to get a fallback value (empty object) if the f?.config
expression evaluate to undefined
:
const { longFieldName } = f?.config || {};
You can use the default values.
const Foo = {}const { config: { longFieldName = "" } = {} } = Fooconsole.log(longFieldName) //''