CodesJava

Easy learning with example program codes

Javascript switch statement tutorial


Javascript switch statement is used to execute a block of statement based on the switch expression value. It is like if else if statement.

Syntax:

switch(expression){ 
case value1: 
//Javascript block of statements 
break;   
case value2: 
//Javascript block of statements 
break;   
...   
default: 
//Javascript block of statements 
break;   
}

JavaScript Switch Statement Example:

<html>
<head>
<script>  
var today;
switch (new Date().getDay()) {
    case 0:
        today = "Sunday";
        break;
    case 1:
        today = "Monday";
        break;
    case 2:
        today = "Tuesday";
        break;
    case 3:
        today = "Wednesday";
        break;
    case 4:
        today = "Thursday";
        break;
    case 5:
        today = "Friday";
        break;
    case  6:
        today = "Saturday";
}
document.write("Today is " + today);
</script>  
</head>
<body>
</body>
</html>

Try it:

JS Bin on jsbin.com
 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki