@djls45
Assuming you mean something like
a ? const1 :
b ? const2 : const3
as
a && const1 ||
b && const2 || const3
well...
as much as I pray no one reads the following as a recommendation to adopt this pattern...
It works, as long as none of the values coming immediately after an && is falsy (which would prevent it from being returned even if the value to its left is truthy).
Test cases:
aTbT -> const1 (Since a is true, a && const1 does not short-circuit, so returns const1. Since const1 is true, it short-circuits both || operators. b && const2 will already be evaluated by the time this occurs since && evaluates before || in JS.)
aTbF -> const1 (Same story as before.)
aFbT -> const2 (a short-circuits the first &&, (b && const2) returns const2 since b is false, a || const2 does not short-circuit since a is false, so returns const2, and const2 || const3 short-circuits and reduces const2.)
aFbF -> const3 (a && const1 and b && const2 both short-circuit, so we're left with a || b || const3, and since a and b are false, none of those || short-circuit, so we finally get const3.)
Inductive proof that this property holds for larger chains is left as an exercise to the reader.