Why is there a break; in the default case?


#1

Hello,

In the Hint section's syntax reminder for lesson All On Your Own, there is a break; after the default case and I was just wondering why it is there (mistake?).

While I'm asking, is it normal behavior that the console makes a sub-indent (instead of one at the same level) for each case which needs to be manually corrected, and no indent at all for the code under the default case?

e.g.:

case "1":
  break;
  case "2":
    break;
    default:
    [code]

Just curious if it's only on my browser or something.

Thanks all,
frisby

https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/1/4?curriculum_id=506324b3a7dffd00020bf661#


Replace this line with your code.


#2

Yes, break is unnecessary in the last block of switch (default in this case). Though it's not a mistake because it doesn't stop the program from running.

Regarding the behavior of code editor ("console" refers to browser console, seen on pressing F12) about adding tab spaces to your code automatically, while it may depend on the editor itself, but regarding the Codecademy editor, yes, after you have finished one case block and written break;, and when you press the [Tab] key, you do also need to press [Backspace] to delete the auto-inserted tab character and restore normal indent for the following case/default block.


#3

Thank you so much, @gaurangtandon! In that case I will be sure to exclude default case breaks and keep an eye out for the indents in switch case.