Answers for "module system in javascript"

1

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
Posted by: Guest on April-24-2021

Code answers related to "module system in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language