Module 5 · Decisions
The Ternary Operator, and Conditions Worth Naming
Free with an accountReading
Zara wrote the gym's door message as one line of code. It had three question marks, three colons and three conditions, and it worked.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
What is inside The Ternary Operator, and Conditions Worth Naming
- The ternary is an expression, so it has a value
- A value, never an effect
- The one idiomatic use: a choice inside printf
- No nesting: name the condition instead
- The type of a ternary comes from both arms