We now have a YouTube Channel. 
Visit complete JavaScript roadmap

← Back to Topics List

Switch Case

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.

Example

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; 
} 

Visit the following resources to learn more:

Open Source

The project is OpenSource, 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Roadmaps Guides Videos About YouTube

roadmap.sh by Kamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© roadmap.sh · FAQs · Terms · Privacy

ThewNewStack

The leading DevOps resource for Kubernetes, cloud-native computing, and the latest in at-scale development, deployment, and management.