Thuta Learning
AdvancedProgrammingbeginner

JS Modules

Relax. We'll talk through this in plain words — no textbook voice.

Modules (ES6) let you split code into separate files and import and export what you need, keeping your code better organized.

Note: For Modules to work in the browser, the HTML <script> tag needs the type="module" attribute.

javascript
// File: utils.js
// export const PI = 3.14;
// export function greet(name) {
//   return `Hello, ${name}!`;
// }

// File: main.js
// import { PI, greet } from './utils.js';
// console.log(PI);
// console.log(greet("World"));

console.log("This is a conceptual example for code organization.");
You should see
This is a conceptual example for code organization.
JS Modules | Thuta Learning