The switch Statement in JavaScript
switch dispatches on a value to labeled case branches using strict (===) comparison — cleaner than long === chains when one variable decides everything. Execution falls through from the matching case into every case below unless break (or return) stops it.
Cases accept any expression, evaluated once against the switch value with ===. default catches unmatched values. switch(true) with boolean case expressions emulates if-chains, though plain ifs usually read better for that shape.
Strict dispatch
switch (day) jumps to the case strictly equal — 3 matches case 3, never case "3".
break stops fallthrough
Without break, execution slides into the next case — end every case with break/return unless sharing deliberately.
default handles the rest
default: runs when nothing matched — the else of the switch world.
Any case expression
Cases can be variables and expressions (not just literals) — all compared with === against the switch value.
let day = 3;switch (day) { case 1: console.log("Mon"); break; case 3: console.log("Wed"); break; default: console.log("other"); break;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.