---
title: "Switch statement in Java Script"  
description: "Whenever we have a multiple options and want to select only one option based on condition then we use concept of switch case statement in java. When w"  
author: "Anonymous User"  
published: 2011-03-10  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/496/switch-statement-in-java-script  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Switch statement in Java Script

Whenever we have a multiple options and want to select only one option based on condition then we use concept of switch case statement in java. When we want to remove complexity of nested if else statement then also we can use concept of “switch case” statement.\

##### Syntax of switch case statement

```
switch( value )       {        case 1:                execute code block 1;                break;       case 2:                execute code block 2;                break;       default:                                execute when any case does not match.                break;       }
```

##### Following example demonstrate use of switch– case statement

```
function dayOfWeak() {            document.write("This example demonstrate use of switch case demo.  <br />");            var val = 5;            switch (val) {                case 1:                    document.write("Sunday.");                    break;                case 2:                    document.write("Monday");                    break;                case 3:                    document.write("Teusday");                    break;                case 4:                    document.write("Wednesday");                    break;                case 5:                    document.write("Thursday");                    break;                case 6:                    document.write("Friday");                    break;                case 7:                    document.write("Saterday");                    break;                default:                    document.write("Invalid date you have selected.");                    break;            }}
```

##### Output of the following code snippet is as follows

![Switch statement in Java Script](https://www.mindstick.com/mindstickarticle/8d9af288-2163-4729-b702-a3bb0c69aee3/images/9ec79320-96b1-43f4-9fcf-3d2de264b8c2.png)

\

---

Original Source: https://www.mindstick.com/articles/496/switch-statement-in-java-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
