1. Java Script Module 2. World Wide Web (WWW) 3. Web Terms 4. NEED FOR SCRIPT 5. Introduction to Internet Programming 6. CLIENT SIDE and SERVER SIDE Scripting 7. Different Scripting Languages 8. Introduction to JavaScript 9. JavaScript and Security 10. How to Enable JavaScript 11. Advantages of Java Script 12. Limitations with JavaScript 13. Difference between JavaScript and JAVA 14. Difference between JavaScript and VBScript 15. JavaScript Development Tools 16. JavaScript Programming Techniques 17. JavaScript terms 18. Starting with JavaScript Programming step by step 19. Time to start JavaScript Programming 20. JavaScript Variables 21. JavaScript RESERVED WORDS 22. JavaScript Data Type 23. NUMBER DATA TYPE 24. BOOLEAN DATA TYPE 25. STRING DATA TYPE 26. NULL DATA TYPE 27. JavaScript Undefined DATA TYPE 28. JavaScript Operators 29. JavaScript Arithmetic Operators 30. JavaScript Logical Operators 31. JavaScript Comparison Operators 32. JavaScript String Operators 33. Bit Manipulation Operators 34. JavaScript Assignment Operators 35. JavaScript Conditional Operator 36. Conversion between JavaScript Data Types 37. Alert JavaScript function 38. confirm JavaScript function 39. prompt JavaScript function 40. JavaScript Statements 41. Single line & Multi-line Comments 42. JavaScrip If Statement 43. JavaScript if..else Statements 44. JavaScript If…else..if statement. 45. JavaScript For Statement 46. JavaScript Statement: 47. JavaScript While Statement 48. JavaScript do while Statement: 49. JavaScript break and continue statement 50. JavaScript switch Statement: 51. JavaScript function() 52. JavaScript function with a Return Value 53. JavaScript with Statement 54. try, catch, and throw Statements 55. JavaScript ARRAY 56. JavaScript array of different data types 57. JavaScript ARRAY and Bubble sorting Program 58. JavaScript Array Methods 59. concate() method 60. every() method 61. filter() method 62. forEach() method 63. indexOf() method 64. Join() method 65. lastIndexOf() method 66. map() method 67. reduce() method 68. reduceRight() method 69. reverse() method 70. some() method 71. toSource() method 72. toString() method 73. pop() method 74. push() method 75. shift () method 76. slice () method 77. splice () method 78. sort() method 79. unshift() method 80. EVENT handling with JavaScript 81. onblur JavaScript Event 82. onchange JavaScript Event 83. onclick JavaScript Event 84. onDblClick JavaScript Event 85. onfocus JavaScript Event 86. onkeydown JavaScript Event 87. onkeyup JavaScript Event 88. Onkeypress JavaScript Event 89. onLoad JavaScript Event 90. onMousedown JavaScript Event 91. onMouseup JavaScript Event 92. Onmouseover JavaScript Event 93. onmouseout JavaScript Event 94. onMouseMove JavaScript Event 95. onReset JavaScript Event 96. onsubmit JavaScript Event 97. onUnload JavaScript Event 98. The Screen Object 99. JavaScript Interview Part1 100. JavaScript Interview Part2 101. JavaScript Interview Part3 102. JavaScript Interview Part4 103. JavaScript Interview Part5 104. JavaScript Interview Part6 105. JavaScript Interview Part7 106. JavaScript Interview Part8 107. JavaScript Interview Part9 108. JavaScript Interview Part10
Pr.Pg Next Pg

switch JavaScript Statement tutorials

  • The "switch" statement helps to evaluate series of expression and execute statement depending upon its value. Instead of checking multiple conditions with if…else, it is cleaner to check it with "switch" statement.

  • The "switch" statement, introduced in JavaScript 1.2.

  • The switch statement is a multi-way decision-making construct that tests wheather an expression matches one of a number of constant values and branches accordingly.

  • The switch statement is a neater alternative to using else-if statements where multi-way decision making is involved.

  • The expression must be enclosed in parentheses, and the body of the switch statement must be enclosed in braces.

  • Statements can be single or multiple statements with or without braces.

  • The values with case should be constants.The expression is evaluted and the resultant value is compared with each of the values given with case.

  • If any of the values match,the statements following the case, till break, are executed.

  • If none of the case values match the result of expression , then the statements following default,which is optional, are executed.

  • The keyword break is used to delimit the scope of the statemants under a particular case.

  • The syntax of switch statement is same as in Java and C++:




case value 1:

statements ;

break ;

case value 2:

statements ;

break ;

case value 3:

statements ;

break ;

default :

statements ;



Example: The following example shows the use of JavaScript switch statement.


message for case 1

message for case 2

message for case 3

message for case default


  • From the above example we have used for loop to explain switch case statement. Here each time the value of i is different and increases as 1, 2, 3, 4. There are three case defined for 1, 2, 3. When value is 4, default is executed.


Example: The following example shows the use of JavaScript switch, Enter month in number and display month in character statement.
Output: August
Output: Entered no is not within 1 to 12


  • From the above example, display to all months in a year for using the switch case:- for the example if we enter the 1, it will display the month is January, 2 will show February and so on.

  • If you enter no outside range from 1 to 12, it will display Entered no is not within 1 to 12 message.


Example: The following example shows the use of JavaScript switch statement and display grade.

Enter Your Grade between A to E




  • The Above program starts with defining a variable Grade, in this program Grade is use to store users choice Grade from A to E, which then is evaluated by a switch statement,

If user choice is A then statement

document.write("Excellent");will be executed,

if user choice is B then statement

document.write("Good"); will be executed,

if user choice is C then Statement

document.write("Ok");will be executed,

if user choice is D then Statement

document.write("Fail...");will be executed,

if user choice is E then Statement

document.write("Fail you have to work very hard");will be executed,

if user choice other character from A to E then statement

document.write("Please enter grade between A to E only."); is executed which is a default statement.

Pr.Pg border                                              Next Pg