All Collections
Online IDE
Using the Sandbox
Importing and Exporting Javascript Modules
Importing and Exporting Javascript Modules

Learn how to import code from third-party libraries, or define your own module for others to use

Sara Jenis avatar
Written by Sara Jenis
Updated over a week ago

In JavaScript, modules are discrete programs that can be imported into other programs as needed. Modules allow the programmer to reuse code or create abstraction boundaries. You can easily import and export modules of your own using CodeHS! See our Javascript Module Tutorial for an interactive guide.

Importing a Module

To import a module, use an import statement such as import modulename from 'moduleaddress' . You can learn more information about different types of import statements here.

Exporting a module

You can create a module and host a module on your site, then load that module in any JavaScript program. See Creating Your Personal Website to learn more about your site.

Once you've created your site, you can add a JavaScript file (ending with .js), then load it using To export the file, you should define a “default” export using export default. To read more about exports, see here.

Still have questions? Contact our team at to learn more!

Did this answer your question?