# Import/Export Business — A JavaScript journey #6

> Do you like to organize your JavaScript projects in multiple and ingeniously split code files, me too! Lucky you (and me), thanks to Webpack or any tool of this kind, \[…\]

Source: https://antistatique.net/en/blog/importexport-business-a-javascript-journey-6

Category: Development

# Import/Export Business — A JavaScript journey #6

Author(s)

[

![Yann](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Yann-G-300x300.jpg)



](/en/agence/yann)

[Yann](/en/agence/yann)25 February 2019

**Do you like to organize your JavaScript projects in multiple and ingeniously split code files, me too!** Lucky you (and me), thanks to Webpack or any tool of this kind, it's getting simpler and simpler, especially with the export / import statements. But when and how do I use them?

## Support

With the ECMAScript 2015 blessing, came the `import` and `export` statements, also known as JavaScript modules or **ES modules**. Very flexible and easy to use, It's sadly not yet supported on every browser (no shit Sherlock), but **also not entirely on NodeJS**.

Node was using **CommonJS** for a long time, but they are working on a Modules Implementation to stay close to the browser implementation. For the moment, it's more stable and safe to use `module.exports` and `require()` on your Node applications, but if you want to follow the progress of the Module Team, I invite you to read the very clear [blog post of Dr. Axel Rauschmayer](http://2ality.com/2018/12/nodejs-esm-phases.html) or to check the official [Github repository](https://github.com/nodejs/modules).

## Basics

The most basic form is when you want to export by default a variable that you've created and use it in another file.

```
// ./addition.js
const addition = (a, b) => a + b;
export default addition;

// ./my-script.js
import addition from './addition.js';
addition(3, 2); // return 5
```

You can also directly export without the need of creating a variable.

```
// ./addition.js
export default (a, b) => a + b;

// ./my-script.js
import addition from './addition.js';
addition(3, 2); // return 5
```

Now, you oftently need to export and import more than one variable, for that you can do something like this :

```
// ./math.js
export const addition = (a, b) => a + b;
export const subtraction = (a, b) => a - b;

// ./my-script.js
import { addition, subtraction }  from './math.js';
addition(3, 2); // returns 5
subtraction(3, 2); // return 1
```

As you can see, no more default export and now, you can import whatever method you want to use elsewhere.

## More advanced

You can also combine targeted variables and default export when importing.

```
// ./math.js
const addition = (a, b) => a + b;
export default { addition };

// ./my-script.js
import math, { addition }  from './math.js';
addition(3, 2); // targeted export, returns 5
math.addition(3, 2); // default export, returns 5
```

When names are not well suited for some cases, you can rename it during export and/or import!

```
// ./math.js
const addition = (a, b) => a + b;
export { addition as sum };

// ./my-script.js
import { sum as foo }  from './test.js';
foo(3, 2); // return 5
```

If there is multiple export, but you want to attach them all to a single item, you can import `*`

```
// ./math.js
export const addition = (a, b) => a + b;
export const subtraction = (a, b) => a - b;

// ./my-script.js
import * as math from './math.js';
math.addition(3, 2); // returns 5
math.subtraction(3, 2); // return 1
```

## Expert mode

When your multiple export module start to (re-)create some kind of monolithic file, it's time to use an **export proxy**.

```
// ./addition.js
export const addition = (a, b) => a + b;

// ./subtraction.js
export const subtraction = (a, b) => a - b;

// ./math.js
export { addition } from './addition.js';
export { subtraction } from './subtraction';

// ./my-script.js
import { addition, subtraction } from './math.js';
addition(3, 2); // returns 5
subtraction(3, 2); // return 1
```

## Conclusion

As you can see, it's a pretty simple topic, but very useful, especially to keep your projects organized and easy to understand. CommonJS was a good start, but import/export statements are really the apotheosis of JavaScript modules management and God, it's so pleasing to write something like `import React, { useState } from 'react';` 😍

## More articles

Author(s)

[

![Anthony](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2024/11/anthony-1-300x300.png)



](/en/agence/anthony-salamone)

[Anthony](/en/agence/anthony-salamone)28 September 2026

### [Smashing Conference Freiburg 2026](/en/blog/smashing-conference-freiburg-2026)

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

[

![Smashing Conference Freiburg 2026 poster](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/assets/blog/smashing-2026.png)



](/en/blog/smashing-conference-freiburg-2026)

Author(s)

[

![Akira](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2025/03/akira-small-300x300.jpg)



](/en/agence/akira-kamata)

[Akira](/en/agence/akira-kamata)22 July 2026

### [Making of : “La nuit des Losers”](/en/blog/making-of-la-nuit-des-losers)

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

[

![Making of : “La nuit des Losers”](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/05/La-nuit-des-Losers-Teaser-1-768x576.png)



](/en/blog/making-of-la-nuit-des-losers)

Author(s)

[

![Pierre](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Pierre-300x300.jpg)



](/en/agence/pierre)

[Pierre](/en/agence/pierre)7 July 2026

### [Dark mode: necessity or trend](/en/blog/dark-mode-necessity-or-trend)

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

[

![Dark mode: necessity or trend](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/07/1-768x384.png)



](/en/blog/dark-mode-necessity-or-trend)
