Languages
[Edit]
EN

JavaScript - export statement

0 points
Created by:
Ela-Davey
663

In this article, we would like to show you how to use the export statement in JavaScript.

Description

Edit

The export statement is used when creating modules that can be used by other programs with the import statement. There are two different types of export, named and default. You can have multiple named exports per module but only one default export.

Syntax

Edit

Named exports:

Default exports:

Note:

Each subsequent export overwrites the previous one.

Practical examples

Edit

Example 1 - using named exports

Edit

module.js file:

index.js file:

Output after running index.js under Node.js:

Example 2 - using default exports

Edit

module.js file:

index.js file:

Output after running index.js under Node.js:

References

Edit
  1. export - JavaScript | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Statements & declarations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join