Switch-4

 

In this example of JavaScript switch statement, we have 4 cases without break statement case 10: output += 'So '; case 1: output += 'What '; output += 'Is '; case 2: output += 'Your '; case 3: output += 'Name'; So if we pass value as 1 in the switch statement and execute all the statements till it find break statement and the output will be "What Is Your Name"? See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p id="sample"></p> <script> var foo = 1; var output = 'Output: '; switch (foo) { case 10: output += 'So '; case 1: output += 'What '; output += 'Is '; case 2: output += 'Your '; case 3: output += 'Name'; case 4: output += '?'; break; case 5: output += '!'; break; default: output+='This is default value.'; } document.getElementById("sample").innerHTML = output; </script> </body> </html>
Output