re: If/else or just if? VIEW POST

VIEW FULL DISCUSSION
 

Another option (for those who favour expressions over statements) can be built out of JavaScript's ternary operator:

return (typeof val === 'string') ? 'A'
     : (val === null || val === undefined) ? 'B'
     : val

Quite a popular pattern.

code of conduct - report abuse