Ram

Lesson 13 of 20

Modules

Split JavaScript into reusable files.

Introduction

Modules export values from one file and import them in another. This keeps code organized and dependencies explicit.

Named exports are useful for several utilities; default exports represent one primary value.

Key insight

Split JavaScript into reusable files.

Example

// math.js
export const add = (a, b) => a + b;

// app.js
import { add } from "./math.js";
console.log(add(2, 3));

This example shows the core modules idea in a small, runnable program.

Real-world example

Large web applications separate API clients, UI components and utility modules.

Test yourself

2-question check

1

What is the main idea in Modules?

2

Where can modules be useful?

Ready to check your understanding?

Answer every question, then submit your quiz.

Try it yourself

JavaScript compiler

Runs in your browser. Nothing is sent to a server.

Output appears here

Practice challenge

Export a function that converts minutes to seconds.

Previous
Next