Lets say I have a object that among other things contain this.
const forest = {house: {kitchen: {table: {bowl: {fruits: ['apple', 'coconut']}}}}
After function goatsinthehouse() the bowl is gone (along with other things). that would make request like this
exampleFruit = forest.house.kitchen.table.bowl.fruits[0]
it go bananas and throw a "try to get from undefined" and crash unless I have a try/catch Currently I use short circuit to get around this. Like this, but there HAVE to be better way.
exampleFruit = forest ||
forest.house ||
forest.house.kitchen ||
forest.house.kitchen.table.bowl ||
forest.house.kitchen.table.bowl.fruits ||
forest.house.kitchen.table.bowl.fruits[0]
? forest.house.kitchen.table.bowl.fruits[0]
: 'None';