A switch works by comparing what is in switch() to every case . works like: if (cnt === 1) … if (cnt === 2) … if (cnt === 3) … Therefore, you can’t have any logic in the case statements .
Read moreCan we write condition in switch case?
No. It’s not possible because a case must be a constant expression.
Read moreWhat is switch case in JavaScript?
The switch statement executes a block of code depending on different cases . The switch statement is a part of JavaScript’s “Conditional” Statements, which are used to perform different actions based on different conditions. Use switch to select one of many blocks of code to be executed.
Read moreCan Switch case be used for String in JavaScript?
JavaScript has both. In a switch statement, the comparison with the cases is via === , and a string instance is not === to a string primitive. …that will turn it back into a primitive, whereupon your switch works.16 Şub 2013
Read more