I've occasionally found the following idiom useful:
a?.b.?.c
can be rewritten as:
((a||{}).b||{}).c
This takes advantage of the fact that getting unknown attributes on an object returns undefined, rather than throwing an exception as it does on null
or undefined
, so we replace null and undefined with an empty object before navigating.