module system in javascript code example
Example: module system in javascript
// Default exports
//Function.js//
export default () => console.log("Hello");
export default someValue = 10;
//Main.js//
import oneFunc from './Function';
oneFunc(); // Hello
import value from './Function';
console.log(value) // 10
// Named exports
//Function.js//
export const sum(a,b) => a+b;
export const sub(a,b) => a-b;
//Main.js//
import {sum,sub} from './Function';
console.log(sum(1, 2)); // 3
console.log(sub(2, 1)); // 1