JavaScript switch statement

The javascript switch statement is used to perform different action based on condition. Below is an example of the switch statement.

    case 1:
      	//run code block 1
    case 2:
      	//run code block 2
    case 3:
	//run code block 3
	//if n is different from case 1, 2 and 3 then run the code under the default case

The break keyword is very important because if we do not use the break keyword then the code will continue on the next case automatically. If the n value is not in any of the 1, 2 or 3 case then the code under the default case will be called. One more thing we need to know here is that the switch statement does not take value other than number so make sure you only pass in the number.