First, credit to the answer at https://stackoverflow.com/a/55944296/901899
Second, if you aren't comfortable with an IIFE (immediately executed function), you will want to check out https://www.tektutorialshub.com/javascript/immediately-invoked-function-expressions-iife/.
Now, because switch() {} is a "statement" in JavaScript and not a function, it can't be IIFE executed with the following
let failure = ( switch(x) { default: return true; } )(x);
You will get: "Uncaught SyntaxError: Unexpected token 'switch'"
This CAN be done using an "immediately-invoked lambda" (like IIFE, but lambda)
let success = ((x) => { switch(x) { default: return true; } })(x);