As you read in the previous lesson that when break
statement is not provided, the execution will continue to the next case's code block. We can take advantage of this feature to handle multiple cases together.
Let us look at an example below:
Here for the roll numbers 8746, 5649, 3268, 7901
the code to be executed is the same: console.log("Congratulations, you have passed the test!");
. So we group them together and write the code to be executed once. We do the same for the other set as well.