JSVerse
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 executes your edits
Loading...
Console
Output will appear here
Visualization
State
Step through — the console panel shows what's happening
Why?

Only one branch ever runs per call — as soon as a test passes, the rest of the chain is skipped entirely.