No. It’s not possible because a case must be a constant expression.
Read moreCan I return from switch case JavaScript?
The JavaScript switch statement can contain return statements if it is present inside a function . The function will return the value in the switch statement and the code after the switch statement will not be executed.17 Tem 2020
Read moreCan I return in switch case?
It’s idiomatic to return from case statements, and it’s “unreachable code” noise otherwise. Personally I would remove the returns and keep the breaks. I would use the switch statement to assign a value to a variable. Then return that variable after the switch statement.
Read moreIs Break necessary in switch case JavaScript?
The break Keyword It is not necessary to break the last case in a switch block . The block breaks (ends) there anyway. Note: If you omit the break statement, the next case will be executed even if the evaluation does not match the case.
Read moreWhat is return () in JavaScript?
The return statement ends function execution and specifies a value to be returned to the function caller .
Read moreCan we use switch case in JavaScript?
The switch case statement in JavaScript is also used for decision making purposes . In some cases, using the switch case statement is seen to be more convenient over if-else statements. Consider a situation when we want to test a variable for hundred different values and based on the test we want to execute some task.25 Oca 2022
Read more