+ 2

Isn't it necessary for a switch statement to have a default case?

23rd Jun 2018, 8:40 AM
Carlewis
Carlewis - avatar
5 Answers
+ 19
No, it's not. In all languages the default case can be omitted. For example, you can find it in a Javascript lesson: https://www.sololearn.com/learn/JavaScript/1139/
23rd Jun 2018, 8:45 AM
Igor Makarsky
Igor Makarsky - avatar
+ 1
its more about discipline and forward thinking.. when u write a program for switch case, if you can anticipate every possible case then you probably can skip default, else it will always give you insight if things go wrong by placing a default handle
29th Sep 2018, 3:21 AM
Ssa.Sak
Ssa.Sak - avatar
0
no...no itsnt neccessary... nothing is neccessary in a switch... not even break;
23rd Jun 2018, 8:43 AM
᠌᠌Code X
᠌᠌Code X - avatar
0
No, It is not.
23rd Jun 2018, 8:54 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
nope
6th Nov 2018, 8:13 PM
Surya