filmov
tv
JavaScript full course part (7)

Показать описание
In JavaScript, the `switch` is used to different actions based on different conditions. It is an alternative to using multiple `if...else` statements The `switch` statement evaluates an matches the expression's value to a case label. If a match is found, code with that case is executed. the basic syntax of aswitch` statement:
```
switch (expression) {
case value1:
// Code to be executed if expression === value1 break;
case value2:
// Code to be executed if expression === value2
break;
value3:
// Code to be executed if expression === value3
break;
default:
// Code to be if expression doesn't any case
}
```
```
switch (expression) {
case value1:
// Code to be executed if expression === value1 break;
case value2:
// Code to be executed if expression === value2
break;
value3:
// Code to be executed if expression === value3
break;
default:
// Code to be if expression doesn't any case
}
```