My goal: to check if the object attribute matches / true. However, in some cases, the object is undefined.
It's not a problem. The script continues normally.
if(somethingUndefined){ }
However, if I try to access the attribute of an undefined object, this will result in an error and stop the script.
if(somethingUndefined.anAttribute){ }
Right now, this is what I'm using to solve the problem:
if(somethingUndefined && somethingUndefined.anAttribute){ }
Is there any other way to do this? Perhaps global parameters that return false if the program tries to access the attribute of an undefined object?
source share