My Problem
Consider a comparison on a nested property of an object:
display.entities.listAfter.text === 'blah';
If one of the properties in the nested lookup does not exist, we would get a type error, for example:
TypeError: Cannot read property 'listAfter' of undefined
What have I tried
Try and catch. Works, but not very elegant and I wonder if there's a better way.
My Wuestion
Is there a canonical way - besides try and catch - to check whether a nested property exists before making a comparison?