I have seen of comments in my JavaScript course that are different from the lesson. I'm confused. I'm a beginner in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I have seen of comments in my JavaScript course that are different from the lesson. I'm confused. I'm a beginner in JavaScript

Some comments say that you can use a DEFAULT statement at the top and apply a BREAK statment but why? Other comments say that you can choose not to apply a BREAK statment after a CASE statment but under which circumstances can you do that

9th Aug 2021, 11:02 PM
Philippe Ezekiel
Philippe Ezekiel - avatar
1 Answer
+ 1
Your question is about SWITCH. It contains of two parts, let me answer one by one. Part One It is counter-intuitive to put the default situation at the start of the switch code block. Switch code blocks should contain the cases one by one and use default at the end to catch any other exceptions. Part Two When you want to give same result for more than one case, you put these cases together and you don't separate them with break. Example: https://code.sololearn.com/cZh6gThD0d11/?ref=app
10th Aug 2021, 3:51 AM
Gordon
Gordon - avatar