In a regular script a function can be invoked by string name as window["myFunc"]().
Is there an equivalent in a JS script of type="module" at the "top level", apart from declaring an object and assigning a method to it?
Thank you.
No - one of the main benefits of modules is to allow code that avoids that sort of global pollution. The top level of a module works similarly to an IIFE - the module can see everything that's global, but nothing can see what's declared inside the module, except that, also:
While you technically can do something like
window.foo = 'foo';
inside a module, writing scripts that use that route defeats the purpose of using a module system at all. Explicit dependencies make code more maintainable.
const foo = 'bar'; are assigned to their environment (which is usually the enclosing block - or top level, if there is no enclosing block). If you're not doing anything weird and understand the hoisting implications, you can consider function fn() { ... to be equivalent to const fn = function() { for most purposes - it's just like the declaration of another variable.