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
JavaScript Classes
JavaScript ES6 Features
JavaScript Error Handling
JavaScript Modules
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is prototype and prototypal inheritance in JavaScript?
What are modules in JavaScript?