What are modules in JavaScript?
// math.js
export const add = (a, b) => a + b;
export default function greet() { return "Hi"; }
// app.js
import greet, { add } from "./math.js";
console.log(add(2, 3), greet());
Output:
Tutorials Class - Output Window
5 Hi
Use <script type="module"> in HTML. See JavaScript Modules.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |