One frustrating aspect of developing a JavaScript app is dealing with nested objects that can potentially cause errors and crash the entire application.
if(result.applicant._id === null || applicant_id !== result.applicant._id.toString()){
console.log('redirect user');
}
Looking at the code above, it's evident that there is a risk involved. What if result.applicant._id is null? In that case, calling toString() on an undefined value will result in an error. How can we ensure that toString() works properly in this scenario?
if(result.applicant._id === null || applicant_id !== (result.applicant._id && result.applicant._id.toString())){}
However, this solution feels messy and involves unnecessary duplication just to check for the existence of a property in JavaScript.