if...else Conditional
Last updated: 2026-09-09
if...else Conditional
if...else executes different code blocks based on a condition.
| Category | Statements |
|---|---|
| ES version | ES1 |
📝 Syntax
if (condition) { ... } else if { ... } else { ... }
⚙️ Parameters
| condition | A boolean expression. |
|---|
Returns:undefined (not an expression).
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Pass
💡 Tip The condition is coerced to boolean — 0/''/null/undefined/NaN are falsy.
ℹ️ info The ternary operator is the expression version of if...else.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| if...else | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qif vs ternary?
ATernary for simple assignment; if...else for complex logic.
QCan the condition be a number?
AYes — coerced to boolean; 0 is falsy.
Qif...else vs switch?
Aswitch for single-value matching; if...else for complex conditions.