My goal: Test if the attribute of an object is/returns true. However, in some cases, the object is undefined.
This works no problem. The script continues normally.
if(somethingUndefined){ }
However, if I try to access an attribute of an undefined object, this generates an error and stops the script.
if(somethingUndefined.anAttribute){ }
Right now, this is what I'm using to solve the problem:
if(somethingUndefined && somethingUndefined.anAttribute){ }
Is there another way to do that? Maybe a global settings that will return false if the program tries to access an attribute of an undefined object?
somethingUndefined && somethingUndefined.anAttributeis a standard practiceif (this.post.featured_image && this.post.featured_image.media_details && this.post.featured_image.media_details.sizes && this.post.featured_image.media_details.sizes.large)