1// Three different export styles
2export foo;
3export default foo;
4export = foo;
5
6// The three matching import styles
7import {foo} from 'blah';
8import foo from 'blah';
9import * as foo from 'blah';
10
1// Exporting individual features
2export let name1, name2, …, nameN; // also var, const
3export let name1 = …, name2 = …, …, nameN; // also var, const
4export function functionName(){...}
5export class ClassName {...}
6
7// Export list
8export { name1, name2, …, nameN };
9
10// Renaming exports
11export { variable1 as name1, variable2 as name2, …, nameN };
12
13// Exporting destructured assignments with renaming
14export const { name1, name2: bar } = o;
15
16// Default exports
17export default expression;
18export default function (…) { … } // also class, function*
19export default function name1(…) { … } // also class, function*
20export { name1 as default, … };
21
22// Aggregating modules
23export * from …; // does not set the default export
24export * as name1 from …; // Draft ECMAScript® 2O21
25export { name1, name2, …, nameN } from …;
26export { import1 as name1, import2 as name2, …, nameN } from …;
27export { default } from …;
1// Exporting individual features
2export let name1, name2, …, nameN; // also var, const
3export let name1 = …, name2 = …, …, nameN; // also var, const
4export function functionName(){...}
5export class ClassName {...}
6
7// Export list
8export { name1, name2, …, nameN };
9
10// Renaming exports
11export { variable1 as name1, variable2 as name2, …, nameN };
12
13// Exporting destructured assignments with renaming
14export const { name1, name2: bar } = o;
15
16// Default exports
17export default expression;
18export default function (…) { … } // also class, function*
19export default function name1(…) { … } // also class, function*
20export { name1 as default, … };
21
22// Aggregating modules
23export * from …; // does not set the default export
24export * as name1 from …;
25export { name1, name2, …, nameN } from …;
26export { import1 as name1, import2 as name2, …, nameN } from …;
27export { default } from …;
1// module "mon-module.js"
2export default function cube(x) {
3 return x * x * x;
4}
5
1export default const array = [1, 2, 3];
2export default let array = [1, 2, 3];
3export default var array = [1, 2, 3];
4export default const variable = 'value';
5export default let variable = 'value';
6export default var variable = 'value';
7export default const variable;
8export default let variable;
9export default var variable;
10export default function functionName () {
11 // ...
12}
13export default class ClassName {
14 // ...
15}
16// Before you use export default: You can't have 2 or more export default's.