Am working in the angular app, I want to optimize some of my conditions. In my code i have number of hierarchical objects, so I have check the existance of parameters like :
if(this.mySettings && this.mySettings.display && this.mySettings.display.sound){
//body of if statement
}
I think this is unneccessary to use number of words to check the param in hierarchy like this. I also used the typeof operator of javascript. like:
if(typeof(this.mySettings.display.sound) !== 'undefined'){
//body of if statement
}
But in this case if display is undefined then it throws an error. If any body knows any better way then please suggest. Thanks in advance!