There is nothing wrong with using let
in this case. Const
is useful for creating non changing variables throughout the file, function or class. For example, storing a non changing base url for http calls (https://your.domain.here/).
Whereas let
and var
are more suited to changing variables such as the amount of time a user clicks on a button, or slider to select a minimum and maximum date/age range.
However, you will want to change your switch statement to a valid statement like so:
switch (input) {
case 1: {
result=x;
break;
}
case 2: {
result=y;
break;
}
case 3: {
result=x;
break;
}
default:
break;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…