Often, I write something like this:
if(model.properties.foo.bar){
// ...
}
else{
// ...
}
Currently, I want to fetch a document only if it isn't already cached. To do so, I write an if-statement like above, checking for the title of the current document.
However, if there is no current document because the user just entered my application, this check will fail due to an undefined model.properties
. An error is thrown and the else
block won't execute.
What is the commonly best practive to write such checks?