In this post, we are going to explain the switch statement in JavaScript with the example. If you want to learn the javascript, then keep your close attention in this post. This post helps you to understand switch statement.
Related Posts: How to Create Tabs Using CSS and JavaScript
Copy the below switch statement example and create a JS file to execute this code snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<script type="text/javascript"> var mychar = "C"; document.write("Checking the character...<br/>"); switch(mychar) { default: document.write(mychar + " is a consonant."); break; case "A": document.write(mychar + " is a vowel."); break; case "E": document.write(mychar + " is a vowel."); break; case "I": document.write(mychar + " is a vowel."); break; case "O": document.write(mychar + " is a vowel."); break; case "U": document.write(mychar + " is a vowel."); break; } document.write("<br/>Done!"); </script> |
Related Posts: JavaScript String Functions With Example
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: javascript switch case string, javascript switch return, javascript switch vs if, Switch statement, switch statement example, Switch statement in JavaScript, using switch statement in javascript