Is it a good practice to end switch with defaults in JavaScript?

HTMLJavascriptProgramming Scripts

Yes, it is a good practice to end switch with defaults. Always end it with defaults.


Let’s see an example of a switch in JavaScript using defaults −

            var grade='A';
            document.write("Entering switch block<br />");
            switch (grade) {
               case 'A': document.write("Good job<br />");

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

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

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

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

               default: document.write("Unknown grade<br />")
            document.write("Exiting switch block");
Updated on 20-May-2020 09:07:59