There are 4 types of exports:
1— Named exports (several per module) 2**— Default exports** (one per module)3 — Mixed named & default exports 4**— Cyclical Dependencies**
//------ lib.js ------export const sqrt = Math.sqrt;export function square(x) { return x * x;}export function diag(x, y) { return sqrt(square(x) + square(y));}//------ main.js ------import { square, diag } from 'lib';console.log(square(11)); // 121console.log(diag(4, 3)); // 5
or
//------ main.js ------import * as lib from 'lib';console.log(lib.square(11)); // 121console.log(lib.diag(4, 3)); // 5
//------ myFunc.js ------export default function () { ... };//------ main1.js ------import myFunc from 'myFunc';myFunc();
//------ underscore.js ------export default function (obj) { ...};export function each(obj, iterator, context) { ...}export { each as forEach };//------ main.js ------import _, { each } from 'underscore';...
// lib.jsimport Main from 'main';var lib = {message: "This Is A Lib"};export { lib as Lib };
// main.jsimport { Lib } from 'lib';export default class Main {// ....}