Is it possible to execute a case block based on a function call/expression evaluation?
function decideRandomName(name) {
let n
switch (name) {
case name.toString().toUpperCase().startsWith("A"): // Is this possible?
console.log("here")
n = "Andshand"
break;
case name.toString().toUpperCase().startsWith("B"):
n = "Bandshand"
break;
default:
n = "Pandu saala"
}
return n;
}
When i execute this, it always executes the default block. If this kind of syntax is not supported then i believe js to throw me an error? Can someone explain the concept here?