I have a method findResult
function findResult(response){
if (response[0].firstProperty.Value > 0)
return true;
else false;
}
In this method, if response object is undefined we get a javascript error. My question is whether to use explicit undefined checks or wrap the code around try/catch as shown below:
function findResult(response){
try{
if (response[0].firstProperty.Value > 0)
return true;
else return false;
}
catch(e){
return false;
}
}
ifvstry()catch(){}does not matter) stackoverflow.com/questions/19727905/… The real question here is whether you want to continue executing code in the same block ifresponseisnull. if the answer is no, it really does not matter which solution you choose