In chrome’s console, when I type:
> switch(3){default:"OK"}
"OK"
So looks like the switch statement has a return value. But when I do:
> var a = switch(3){default:"OK"}
It throws a syntax error “Unexpected Token switch”
Is it possible to capture the return statement of the switch?
That’s because when you’re putting that into the Chrome console, you’re short-circuiting it. It’s just printing ‘OK’ because it’s reaching the default case, not actually returning something.
If you want something returned, stick it in a function, and return the ‘OK’ from in the default case.