#Variable Scope issue

1 messages · Page 1 of 1 (latest)

stark kernel
idle quarry
#

Variables in ESM modules are scoped to the modules, you can only access them in other modules by exporting them and using import in the other module, like you did for the counter.
More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

If you want to bypass this, you can always set something on window object to make it global, but that should be used only exceptionally

This guide gives you all you need to get started with JavaScript module syntax.