The switch statement is used to select one block of many code blocks to be executed.
Syntax
switch(expression){
case x:
//code block
break;
case y:
//code block
break;
default:
//code block
}
Example
var x = 1;
switch (x) {
case 1:
text = "One";
break;
case 2:
text = "Two";
break;
default:
text = "No value found";
}
Copyright ©2022 coderraj.com. All Rights Reserved.