mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-02-24 11:33:09 +01:00
Add JavaScript switch statement (#1822)
* Update 101-switch.md * Update content/roadmaps/106-javascript/content/107-javascript-control-flow/101-conditional-statements/101-switch.md Co-authored-by: Kamran Ahmed <kamranahmed.se@gmail.com>
This commit is contained in:
parent
5ac74ddd6c
commit
1c0fd98625
@ -1 +1,25 @@
|
||||
# Switch
|
||||
# Switch
|
||||
|
||||
The `switch` statement evaluates an expression, matching the expression's value against a series of `case` clauses, and executes statements after the first `case` clause with a matching value, until a `break` statement is encountered. The `default` clause of a `switch` statement will be jumped to if no `case` matches the expression's value.
|
||||
|
||||
```
|
||||
switch (expression) {
|
||||
case value1:
|
||||
//Statements executed when the result of expression matches value1
|
||||
break;
|
||||
case value2:
|
||||
//Statements executed when the result of expression matches value2
|
||||
break;
|
||||
...
|
||||
case valueN:
|
||||
//Statements executed when the result of expression matches valueN
|
||||
break;
|
||||
default:
|
||||
//Statements executed when none of the values match the value of the expression
|
||||
break;
|
||||
}
|
||||
```
|
||||
|
||||
<ResourceGroupTitle>Free Content</ResourceGroupTitle>
|
||||
<BadgeLink colorScheme='blue' badgeText='Read' href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch'>switch - MDN</BadgeLink>
|
||||
<BadgeLink colorScheme='blue' badgeText='Read' href='https://javascript.info/switch'>The switch statement</BadgeLink>
|
||||
|
Loading…
x
Reference in New Issue
Block a user