Fundamentals / Conditions
Conditions
if / else, switch, and the ternary — three ways to pick a path.
Conditions branch execution. `if / else if / else` reads top to bottom and runs the first branch whose test is true. `switch` compares one value against several cases with strict equality. The ternary `condition ? a : b` is an expression, so it can sit inline anywhere a value is expected.
Codeeditable — Run and Step both follow your edits
Loading...
Console
Output will appear here
Visualization
Result
Press Step to watch each line's result appear here
Why?
Only one branch ever runs per call — as soon as a test passes, the rest of the chain is skipped entirely.