Today I realized that I'm missing some important theory in JS. In our app written in TypeScript we have tons of constants (objects) declared within their own modules that are imported and used elsewhere in the app. Those constants are generally quite big settings objects that have tons of properties (as well as some functions as properties).
While our app is growing I started to worry about performance and optimization. The idea that came into my head was to wrap each of those constants into a function, returning the constant so that it's only loaded into memory once that function is called.
I'm not 100% sure that this is how it will work. Specifically, if I declare a function that defines a constant and returns it, what exactly will be in memory when I import that function? How will it be different from when I define a constant and import it straight away? Does it make sense to wrap such constants into functions?
At the moment I assume that once I define a constant within a module scope it's loaded into memory once it's imported. Is it correct?
Please let me know if there's some better approach to handle this.