# JavaScript, how to export a function

> Learn how to export a function from a JavaScript file using export default, then bring it into another file with a matching import statement.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-11-10 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-export-a-function-javascript/

In [JavaScript](https://flaviocopes.com/javascript/) we can separate a program into separate files. How do we make a function we define in a file available to other files?

You typically write a function, like this:

```js
function sum(a, b) {
  return a + b
}
```

and you can make it available for any other file using this syntax:

```js
export default sum
```

We call it a **default export**.

The files that need the function exported will import it using this syntax:

```js
import sum from 'myfile'
```
