The best thing about switch statements is that you're not limited to strings.
functionfun(data){switch(data.constructor){caseSymbol:return'You gave me a symbol';caseString:return'No strings attached';caseArray:return'To map or not to map';caseNumber:return'something something 42';caseBoolean:return'is it true?';casePromise:return'maybe, maybe not';caseFunction:return"Don't call us, we'll call you";case(async()=>{}).constructor:return'Ooh, fancy stuff';default:return'what?'}}constsome_fun=function(){};constasync_fun=asyncfunction(){};fun(['hello']);fun(74);fun('this');fun(Symbol('What?'));fun(true);fun(some_fun);fun(async_fun);
I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
The best thing about switch statements is that you're not limited to strings.
Nice. Thanks for sharing