I think this statement might be conflating declaring a variable and instantiating a value. While I’m not deeply familiar with the internals of the JavaScript runtime, I would expect that declaring a local variable would only set aside an additional temporary slot on the stack (just enough to hold a reference) which would be freed as soon as the scope is left.
I’m not sure if each case statement would count as a different scope or not, but worst case for memory (where all the case statements are in the same scope), each declared variable would just be one additional slot pushed temporarily to the stack. Whether each case statement gets its own const
, or you have a single shared variable for them to share, only one case statement will actually get executed, so only that one object instantiation would actually take place; the impact on heap memory should be the same either way.