-3
In this example.
switch(numero {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': console.log('Case 9');
break;
The instruction is falling in case 9, when the number = '2', I know this happens because the break instruction was not used in case '2', but why this happens, since '2' is different from '9'?
Switch is cascade effect by default in javascript, some languages are not. So it’s not a code error, it’s just standard behavior that you have to adapt in each language. It’s like English and Portuguese, things change order and there’s nothing wrong with that, but if we want to do it right, we have to learn and execute it the way each of us.
– Leonardo Getulio