In JavaScript, you can combine multiple case statements in a switch statement to execute the same block of code for different cases. Combining cases can help reduce redundancy and make your code more concise.
Syntax:
switch (expression) {
case value1:
case value2:
case value3:
// Code to be executed for value1, value2, and value3
break;
case value4:
// Code to be executed for value4
break;
// More cases can be added here
default:
// Code to be executed if the expression does not match any of the cases
break;
}
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tutor Joes</title> </head> <body> <script src="js/script.js"></script> </body> </html>To download raw file Click Here
let letter='p'; switch(letter) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'A': case 'E': case 'I': case 'O': case 'U': console.log(letter+" is an Vowel"); break; default: console.log(letter+" is not a Vowel"); break; }To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions