Hacker News new | ask | show | jobs
by masswerk 2547 days ago
Regarding nested ternaries, while not recommended, short circuit evaluations may be even more readable:

return ( (cA && cB && "A & B") || (cA && "A") || (cB && "B") || "neither" );

1 comments

Quick, it's another case of Javsacript Stockholm Syndrome!
:-)

However, this would also work in Perl, etc, (anything featuring short-circuit evaluation and type coercion for evaluating conditions.)