# named export

[JS](../../..) ⟩ [module](../..) ⟩ [ES](..) ⟩ [export]() ⟩ named export

{% hint style="success" %}
```javascript
// export variables declared elsewhere
export { f1, f2 };    

// export declarations
export let a = Math.sqrt(2);
export function f() { ... };
```
{% endhint %}

{% tabs %}
{% tab title="💈 範例" %}
* replit：[named exports](https://replit.com/@pegasusroe/named-exports#math.js)

```javascript
// math.js

// ⭐️ named exports
export function add(a, b) { return a + b }
export function subtract(a, b) { return a - b }
export function multiply(a, b) { return a * b }
export function divide(a, b) { return a / b }
```

📁 index.js&#x20;

```javascript
// ⭐️ import "named exports"
import { add, subtract, multiply, divide } from './math.js';

[
    add(1, 2),         // 3
    subtract(1, 2),    // -1
    multiply(1, 2),    // 2
    divide(1, 2),      // 0.5
    
].forEach(x => console.log(x));
```
{% endtab %}

{% tab title="👥 相關" %}
* ⛔ [<mark style="color:red;">**SyntaxError**</mark>](../../../err/syntax)：[<mark style="color:yellow;">**Named export 'xxx' not found**</mark>](../../../err/syntax/named-export-not-found):exclamation:
{% endtab %}

{% tab title="📗 參考" %}
* [ ] MakeUseOf ⟩ [How to Import and Export Functions in JavaScript](https://www.makeuseof.com/how-to-import-and-export-functions-in-javascript/)
{% endtab %}

{% tab title="📘 手冊" %}
* [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
{% endtab %}
{% endtabs %}
