It depends on the case, but I would probably pick a mixed case like this:
if (typeof val === 'string') {
return 'A';
}
if (!val) {
return 'B';
}
return val;
The main reason is because blocks are in my opinion better to see and less confusing. I also try to avoid the tenary operator, but it really depends on the case. Sometimes it's just perfect. There is no need to write an else in this case. The else if wouldn't improve any performance, and for me it's better to have no else case at all.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It depends on the case, but I would probably pick a mixed case like this:
if (typeof val === 'string') {
return 'A';
}
if (!val) {
return 'B';
}
return val;
The main reason is because blocks are in my opinion better to see and less confusing. I also try to avoid the tenary operator, but it really depends on the case. Sometimes it's just perfect. There is no need to write an else in this case. The else if wouldn't improve any performance, and for me it's better to have no else case at all.