When developing a module in JavaScript, the export statement is used to export live bindings to functions, objects, or primitive values from the module. These data can be used by other modules, app with the import statement.
Exported modules are in strict mode whether you declare them as such or not.
// Exporting individual features export let age = 20, name = 'Tester'; // Export list export { 10, 20.50, 'Templates', [0,1,2,3,4] }; //Exporting everything at once export { object, number, x, y, boolean, string } // Renaming exports export { variable1 as newName1, variable2 as newName2}; //export function export function functionName(a){ return a*10; } // export funcitons, vriables declared earlier export { function1, function2, variable1, variable2 };
There are two types of export, named and default. You can have multiple named exports per module but only one default export.
Named exports are useful to export several values while default exports are useful to export only a single object, function, variable.
export default functionname () { ... } export default className { .. }