Javascript switch case - default parameter causing error
I have some code that defines behavior based on which input the code is processing at that moment. The code looks something like this:
switch(inputOption.name) {
case 'NAME_1':
switch(inputOption.type.toLowerCase()) {
case 'radio':
//some code
case 'text':
//some code
...
case 'image':
//some code
default:
return inputOption.value;
break;
}
break;
default:
break;
}
Some cascading cases are also included in the code. The default parameter raises an error. The error is listed as
the default case is already defined
What is causing this error? The error shows up in the package folder, but the file shows no errors in the package view, but it shows errors when opening the file. I assumed it had something to do with the second default declaration, but was unable to remove it.
+3
source to share
1 answer
You will miss the break statement for your "NAME_1" outer case
switch(inputOption.name) {
case 'NAME_1':
switch(inputOption.type.toLowerCase()) {
case 'radio':
//some code
case 'text':
//some code
...
case 'image':
//some code
default:
return inputOption.value;
break;
}
break; // <-------------------------------------------------- ADD THIS
default:
break;
}
0
source to share