Ternary Operator
The ternary operator is a shorthand for if/else statements. It's the only JavaScript operator that takes three operands.
Basic Syntax
condition ? valueIfTrue : valueIfFalse
Loading JavaScript Playground...
Practical Examples
Loading JavaScript Playground...
Ternary with Function Calls
Loading JavaScript Playground...
Nested Ternary (Use Sparingly)
Loading JavaScript Playground...
Exercise: Max Value
Use ternary to find the larger of two numbers:
Loading JavaScript Exercise...
Exercise: Fee Calculator
Calculate a fee based on membership status:
Loading JavaScript Exercise...
Up next · Lesson 14 of 37
If/Else Statements
1 min read
13 of 37 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

