JAVASCRIPT CLIMBSChapter 2 · JS Conditionals & Logic
Ternary Operator
The ternary operator is a shorthand for simple if-else blocks. It takes a condition followed by a question mark ?, then the expression to run if true, a colon :, and the expression to run if false.
Worked example
How it reads
- score >= 50 is evaluated as the condition
- Pass is returned if the condition is true, Fail if false

Cloud tip: Ternaries are expressions, meaning they resolve to a value that can be assigned directly to a variable.


