Classic scripts vs. module scripts in JavaScript

Here are the differences I have noted from various articles. If you want more details, read a complete article on the internet:

  1. Modules are singleton. They will be loaded and executed only once.
  2. Modules can use import and export.
  3. Modules are always executed in strict mode.
  4. All objects (class, const, function, let, or var) are private unless explicitly exported.
  5. The value of this is undefined at the outer scope (not window).
  6. Modules are loaded asynchronously.
  7. Modules are loaded using CORS. see Access-Control-Allow-Origin: *.
  8. Modules don’t send cookies and authentication info by default. See crossorigin="use-credentials".
  9. Imports are resolved statically at load time rather than dynamically at runtime.
  10. HTML comments are not allowed.

Leave a Comment