JS ⟩ module ⟩ ES ⟩ export ⟩ named export
// export variables declared elsewhere export { f1, f2 }; // export declarations export let a = Math.sqrt(2); export function f() { ... };
replit:named exports
// math.js // ⭐️ named exports export function add(a, b) { return a + b } export function subtract(a, b) { return a - b } export function multiply(a, b) { return a * b } export function divide(a, b) { return a / b }
📁 index.js
// ⭐️ import "named exports" import { add, subtract, multiply, divide } from './math.js'; [ add(1, 2), // 3 subtract(1, 2), // -1 multiply(1, 2), // 2 divide(1, 2), // 0.5 ].forEach(x => console.log(x));
⛔ SyntaxError:Named export 'xxx' not found❗
MakeUseOf ⟩ How to Import and Export Functions in JavaScript
export
Last updated 1 year ago