if / else
Branching based on conditions.
Syntax
if (condition) { ... } else { ... }Description
The condition is written in parentheses; if true, the first block runs, otherwise the else block runs. Intermediate conditions use else if. Curly braces are not mandatory for a single line.
Example
Loading editor…
Expected output
Adult
When to use?
Decision making, input control.