In my project I constantly come across this type of conditional expression:
if(cliente && cliente.id) {
return cliente.id;
} else {
return '';
}
That is, "if there is a client and this client has an id then return the value of the id, otherwise return an empty string" . This expression is useful for two reasons;
1- Avoid exceptions of type Cannot read property of undefined/null
2- Do not return the literal undefined
for the interface
Is there any way to reduce this expression?
Note: The value of zero is not part of the possible ids .