Skip to content

Day 4: ES Modules (import & export)

Organize codebase architecture into modular files using standard ES Modules (import and export).

math.js
export const add = (a, b) => a + b;
export default function multiply(a, b) { return a * b; }
// main.js
import multiply, { add } from './math.js';
console.log(add(2, 3));

In HTML:

<script type="module" src="main.js"></script>
  1. Create a utils.js module exporting helper functions and import them in app.js.