How to come out of a switch case in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To come out of a switch case, use the break statement. The break statements indicate the end of a particular case. If they were omitted, the interpreter would continue executing each statement in each of the following cases.

Example

You can try to run the following example to implement switch-case statement, which uses break statement

Live Demo

<html>
   <body>
      <script>
         var grade='A';
         document.write("Entering switch block<br>");

         switch (grade) {
            case 'A': document.write("Excellent<br />");
            break;

            case 'B': document.write("Very good<br />");
            break;

            case 'C': document.write("Passed<br />");
            break;

            case 'D': document.write("Not so good<br />");
            break;

            case 'F': document.write("Failed<br />");
            break;

            default: document.write("Unknown grade<br />")
         }
         document.write("Exiting switch block");
      </script>
   </body>
</html>
raja
Published on 08-Feb-2018 11:09:31
Advertisements