Switch Case Statement In Javascript #16 | Complete Javascript Tutorials |

Publié le: 01 janvier 1970
sur la chaîne: Utkarsh Gupta
22
1

In this video we have give information regarding the switch case statement which we use in javascript language.

The JavaScript Switch Statement
Use the switch statement to select one of many code blocks to be executed.

Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
This is how it works:

The switch expression is evaluated once.
The value of the expression is compared with the values of each case.
If there is a match, the associated block of code is executed.
If there is no match, the default code block is executed.
Example
The getDay() method returns the weekday as a number between 0 and 6.

(Sunday=0, Monday=1, Tuesday=2 ..)

This example uses the weekday number to calculate the weekday name:

switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
The result of day will be:

Wednesday

#javascript
#coding #coding
#css
#html
#webdeveloper
#webdevelopment
#codeschool
#codelife


Sur cette page du site, vous pouvez voir la vidéo en ligne Switch Case Statement In Javascript #16 | Complete Javascript Tutorials | durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Utkarsh Gupta 01 janvier 1970, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 22 fois et il a aimé 1 téléspectateurs. Bon visionnage!