Import and Export
Share functions across files with named exports and one default export.
This lesson uses <script type="module">. Open it through a local
HTTP server (not file://) so the browser can load sibling modules.
Results appear here.
Important JavaScript
// 09-math-utils.js — many named exports
export function add(a, b) { return a + b; }
export function multiply(a, b) { return a * b; }
// 09-greet-default.js — one default export per module
export default function greet(name) {
return "Hello, " + name + "!";
}
// 09-import-export.js
import { add, multiply } from "./09-math-utils.js";
import greet from "./09-greet-default.js";