switch Multi-branch switch
Last updated: 2026-09-09
switch Multi-branch switch
switch matches an expression against case branches. Don't forget break!
| Category | Statements |
|---|---|
| ES version | ES1 |
📝 Syntax
switch (expr) {
case v1: ...; break;
default: ...;
}
⚙️ Parameters
| expression | The expression to match. |
|---|
Returns:undefined.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Weekday
⚠️ Warning Missing break causes fall-through — sometimes intentional.
💡 Tip switch uses strict equality (===) — no type coercion.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| switch | ✓ 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
QIs switch strict?
AYes — uses ===.
QWhat is fall-through?
AContinuing to the next case without break.
Qswitch or if...else?
Aswitch for multi-value matching; if...else for ranges.