[Solved] How does the ternary operator work exactly works in with multiple coupled ternary operators? [closed]


Your confusion is common and is exactly why I avoid chaining ternary operators, even when I find them readable myself.

condition1 ? yes : condition2 ? yes : condition3 ? yes : no

If it helps, think of it as having parentheses:

condition1 ? yes : (condition2 ? yes : (condition3 ? yes : no))

The second expression is the “false” action for the first expression, and the third is the “false” action for the second. It would get even harder to follow if one ternary expression were the “true” action for another.

solved How does the ternary operator work exactly works in with multiple coupled ternary operators? [closed]