return (typeof val === 'string') ? 'A'
: (val === null || val === undefined) ? 'B'
Quite a popular pattern.
Ternary operators are really nice for simple and small statements, but I definitely wouldn't recommend them for anything complex. Makes things to hard to read for me. The same could be said for other developers.
I always put a LOT of parentheses around the ternary operators, and enforce a style that looks like this:
((typeof val === 'string')
: ((val === null || val === undefined)
In general, I consider operator precedence to be a footgun, as it makes things more complex than they need to be. I find symbolic expressions to be much more readable, as there is no need to even understand what functions do to see the order of application.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.