Skip to main content
All CollectionsOnline IDEUsing 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 6 months 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.

Screenshot of the CodeHS JavaScript editor and importing a module

Exporting a module

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

Once you've created your CodeHS.me site, you can add a JavaScript file (ending with .js), then load it using https://yourusername.codehs.me/filename.js. 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 hello@codehs.com to learn more!

Did this answer your question?