Short answer
A switch tests one value and runs the matching branch. JavaScript, C, and C++ fall through without break, while C# rejects that fall-through and Python uses match instead of switch. MDN says JavaScript compares with strict equality. Python match, added in 3.10, does not try later patterns after a hit.
Last verified against the sources listed below.
Key takeaways
- MDN: JavaScript switch uses strict equality, and a missing break falls through.
- The C reference requires an integer expression, and case labels fall through without break.
- C++ also falls through. Since C++17, [[fallthrough]] marks an intentional fall.
- C# forbids falling from one switch section into the next. The section must end with break, goto, or return.
- Python has no switch keyword. match and case arrived in Python 3.10.
What is switch statement selection? It is one value, then a list of branches, with a language-specific rule about whether the next branch runs too.
Programming paradigms include this kind of choice.
JavaScript spells it switch.
Python does not. It spells the idea match. The table below is the difference that actually changes a program.
What does switch do?
Switch evaluates one expression and starts running at the first matching case.
MDN says JavaScript uses strict equality, so 1 does not match '1'. The match starts at that case and continues until break, return, or the end of the statement. default is optional, and only one is allowed.
Multiple default clauses are a syntax error.
C, on cppreference, is narrower about the value. The expression must have integer type. Case labels are integer constant expressions, and the values must be unique after conversion to the promoted type.
At most one default is allowed in that switch. A nested switch may reuse a number.
Do cases fall through?
In JavaScript, C, and C++, yes, unless you stop them. In C# and in Python’s match, no.
| Language | Keyword | Fall-through | How you stop or mark it |
|---|---|---|---|
| JavaScript | switch / case |
Yes, if break is missing |
break, or return inside a function |
| C | switch / case |
Yes. The reference prints the next label too | break |
| C++ | switch / case |
Yes. Labels do not divert flow by themselves | break. [[fallthrough]] since C++17 |
| C# | switch / case |
No. A fall into the next section is an error | End the section with break, goto, or return |
| Python | match / case |
No switch. A selected case does not try the next pattern |
A guard can reject a pattern and move on |
MDN’s worked example sets foo to 0, matches case 0, and also prints the body of case 1 because the first arm forgot break. The log is 0 and then 1. Stacking case "Mangoes": and case "Papayas": with one break is the intentional form: several values, one body.
The C page shows the same accident. switch(1) with case 1 and case 2 and no break prints both lines. C++ repeats that example and adds the C++17 attribute [[fallthrough]] so a compiler warning can be silenced when the fall is on purpose.
C# will not compile a section that falls into the next one. Microsoft’s reference says every section ends with break, goto, or return. Several labels may share one section, which is how you cover more than one value without fall-through.
Patterns can be relational, such as case < 0.0:, and a when guard can add a Boolean test.
Python’s reference, in section 8.6, says match was added in version 3.10. The flow is: evaluate the subject, try patterns in order, and if the pattern works and the guard passes, run that block. The sample output is only Case 3, y: 200.
The comment on the next arm says the pattern was not attempted. There is no break to write, because control does not leak downward.
Where does each language differ?
C and C++ want an integral value. JavaScript will switch on a string. Python matches a structure, not only a constant.
C++ can also declare the value in the switch, including an init-statement since C++17. The page warns that a jump must not enter the scope of a variable that was not initialized, so a case that declares a local usually needs its own braces.
JavaScript has a similar trap for const and let: the whole switch is one block, so wrap each arm in braces if both arms declare the same name.
Python patterns can bind names, and those bindings outlive the block. A guard is an if on the case. Guards run in order and stop once a case is selected.
An irrefutable pattern, such as _ or a bare name, with no guard, has to be the last case, and there can be only one.
C# evaluates patterns from top to bottom and errors if an earlier arm already makes a later arm unreachable. default can sit in the middle. It still runs only when nothing else matched, unless you goto default.
What should you watch for?
Write the stop, or the language’s equivalent, in the same edit as the new case.
- In JavaScript, add
breakunless the next case is supposed to run. - In C and C++, do the same, and in C++ add
[[fallthrough]]when the fall is deliberate and the compiler warns. - In C#, stack labels on one section instead of leaving a section without
break. - In Python, write
matchandcase, and put the catch-all last. - Do not paste a JavaScript
switchinto a Python file and expect it to parse.
A character counter can check the length of a case label. It will not insert the break. The bug that ships is usually the missing stop, not the length of the word.
If the branches are really different types of data, Python’s structural patterns say more than a chain of integer cases. If the value is a small integer or a short string and every arm is a different action, switch in JavaScript, C, C++, or C# is the direct tool, as long as you follow that language’s fall-through rule and not the neighbor’s. ## How do you choose the keyword?
Use the keyword the language actually has, and copy its fall-through rule with it.
JavaScript, C, C++, and C# spell the statement switch. Python spells it match, and only since 3.10. Pasting switch into a Python file is a syntax error, not a style nit.
Pasting match into a JavaScript file is the same kind of error.
After the keyword is right, write the stop that language expects. Break in JavaScript, C, and C++. A required exit in C#.
Nothing extra in Python, because a selected case does not continue. A character count will not catch a missing break. A test with two adjacent cases will.
Frequently asked questions
What is a switch statement in JavaScript?
MDN says a switch evaluates an expression, finds the first case whose value is strictly equal, and runs from there until a break or the end of the switch. If you omit break, execution continues into the next case even when that case does not match. That is fall-through. The default clause runs when nothing matches, and a switch may have only one default.
What is a switch statement in C or C++?
Cppreference says a C switch tests an integer expression, including char and enumerations, against case labels whose constant values are unique. Without break, control falls into the next label. The C++ page says the same about labels: they do not themselves change the flow, so you use break to leave. Since C++17, compilers may warn on a fall-through unless [[fallthrough]] sits immediately before the next case.
What is a switch statement in Python?
Python does not have a switch statement. The language reference adds match in Python 3.10. You write match on a subject, then one or more case blocks. If the pattern succeeds and the guard is missing or true, that block runs. The reference's sample marks the following pattern as not attempted, so a selected case does not fall through. match and case are soft keywords.
What is a switch statement in C#?
Microsoft's C# reference says switch selects a statement list by pattern, checked from top to bottom. Control cannot fall through from one switch section to the next. Every section must end with break, goto, or return, and falling through is a compiler error. You can stack several case labels on one section when they share a body. The default arm can sit anywhere, and it runs only when no other pattern matches, unless a goto default jumps there. A when guard can narrow a pattern that matched.
What is a switch statement in JS if I forget break?
JS here means JavaScript, and MDN's rule is the one above. Forgetting break is not a syntax error. The next case runs too, including default if you fall into it. The page's example with the value 0 logs both 0 and 1 because the matching case has no break. Use break when each arm should stop. Leave the break out only when you mean several labels to share one action, which MDN shows by stacking case lines with a single break at the end.
Sources
- switch · MDN, 2026
- The match statement · Python Software Foundation, 2026
- switch statement (C) · cppreference, 2026
- switch statement (C++) · cppreference, 2026
- if and switch statements · Microsoft Learn, 2026