Both xand yin a ? x : yare full expressions, so you are allowed to insert any subexpressions into them while they produce the results of the correct type.
However, nesting conditional expressions quickly becomes unmanageable, so using parentheses is a very good idea:
let res = a ? (b ? x : y) : z
or
let res = a ? x : (b ? y : z)
or even
let res = a ? (b ? w : x) : (c ? y : z)
source
share