if / else
Branching based on conditions.
Syntax
if (condition) { ... } else { ... }Description
The condition is written inside parentheses; if true, the first block runs, otherwise the else block runs. else if is used for intermediate conditions.
Example
Loading editor…
Expected output
Adult
When to use?
Decision making, input control.