if / else
Runs different code based on a condition.
Syntax
if (condition) { ... } else { ... }Description
The condition is written inside parentheses, and blocks are written inside curly braces { }. Intermediate conditions are added with else if.
Example
Loading editor…
Expected output
Passed
When to use?
Access control, flow branching.
Common mistakes
- ⚠️ Use === for equality (== can do type coercion and cause unexpected behavior).