Use Optional Chaining to Safely Handle Objects with Unknown Properties
Optional Chaining provides a safe way to handle situations where you don't know whether specific properties exist on a given object. Rather than resorting to long conditional logic or nested ternaries, optional chaining is a concise way to only access properties if they exist - and if they don't, to return undefined rather than throw an error.
Please note: This feature is still making its way through the TC39 proposal process. To use it in your project today, you can enable it using Babel's Optional Chaining plugin.