Utilizor
Contact Us

Switch Structure

The switch statement syntax.

Switch Structure

The switch statement is used to perform different actions based on different conditions.

Use the switch statement to select one of many code blocks to be executed.

switch(expression) { case x: // code block break; case y: // code block break; default: // code block }

Example

switch(new Date().getDay()) {
  case 0:
    day = "Sunday";
    break;
  case 1:
    day = "Monday";
    break;
}