ES6 module scope
You can do globalThis.a = "a"
and access it after that module has loaded. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
Can I use "a" variable in a global scope after module importing or is it available only in a module scope?
It's only available inside the module it was declared in.
Will ES6 modules have a similar working principle like this trick: [...]
Basically yes.
ES6 has these kinds of scopes, order from "top" to "bottom":
- Global scope
- Module scope
- Function scope
- Block scope