In order to prevent using an object's value that doesn't exist (which would throw an error), I usually do something like this:
if(apple.details){
// do something with apple.details
}
and it normally works fine. But if it's about a "object's object's value", like apple.details.price
, that doesn't work, because if not even .details
exists, the if()
would throw an error.
What can I do or is there generally a better way to do this?