0
  1. I noticed that when adding type="module" to a script tag in HTML with src="./someJS.js", variables from this JS file are not accessible from the browser console and appear as undefined. This differs from the same HTML tag without the module indication, where all variables can be perfectly viewed from the browser.

I would like to ask for a detailed explanation regarding this behavior.

  1. Additionally, I would like to ask if using type="module" is mandatory when using an import statement within the JS file I am loading into the HTML or if there is any way to get around this.

Thank you very much!

RodrigoR
  • 21
  • 3
  • Related https://stackoverflow.com/questions/48612021/how-to-declare-global-variable-in-module-script – Konrad Mar 24 '23 at 08:22
  • *Module-defined variables are scoped to the module unless explicitly attached to the global object. On the other hand, globally-defined variables are available within the module. For example, given the following code:* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules – Konrad Mar 24 '23 at 08:23

0 Answers0