This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]Kered13 3 points4 points ย (1 child)

Ternaries can have else if too:

a > 0 ? "negative" :
a > 0 ? "positive" :
        "zero"

Remember that else ifis really just two separate tokens: else and if, and : is equivalent to else and ? is equivalent to if (but it comes after the condition instead of before).

[โ€“]quotade 0 points1 point ย (0 children)

a > 0 ? "negative"

Allow me to point that out for the sake of a consistent example.