Member-only story
Javascript Basics — “export”
2 min readJan 7, 2020
The export
statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import
statement.
There are two different types of export.
- named
- default
You can have multiple named exports per module but only one default export.
Named Export
- Useful to export several values at once
- Zero or more exports per module
- During the import, it is important to use the same name
- With named exports you can exporting and importing any functions, objects, or primitive values with the defined name
- Mandatory to use the same name of the corresponding object
// Exporting individual features
export let name1, name2, …, nameN; // also var, const
export let name1 = …, name2 = …, …, nameN; // also var, const
export function functionName(){...}
export class ClassName {...}
// Export list
export { name1, name2, …, nameN };
// Renaming exports
export { variable1 as name1, variable2 as name2, …, nameN };
// Exporting destructured assignments with renaming
export const { name1, name2: bar } = o;