DEV Community

Discussion on: If/else or just if?

Collapse
 
noahlaux profile image
Noah Laux

In favor of not having a if/else block if I can avoid it.

return typeof val === 'string' && 'A' ||
     val === null || val === undefined && 'B' || val;

or to be a little more descriptive

const isString = typeof val === 'string';
const isEmpty = val === null || val === undefined;

return isString && 'A' || isEmpty && 'B' || val;