JavaScript Modules
Last updated
Was this helpful?
Last updated
Was this helpful?
JavaScript, before 2015, had no language-level module syntax. But as JS applications became more and more complex, the need to split code into multiple files (or modules) became apparent. Node.js adopted the and still uses it today. JavaScript's native module system was standardised in 2015 and is now supported by all major browsers and Node.js.
components/header.js
initialise.js
components/auth.js
initialise.js
components/auth.js
initialise.js
Instead of adding multiple script tags, choose an entry point (e.g. initialise.js
) and include that in a script tag with a type attribute of "module":
You can then use import/export
in your JS files.
initialise.js