mediumFrontend

What are modules in JavaScript?

941 views
01

Understand the problem

Assesses knowledge of modern JavaScript's approach to code organization and reusability.

moduleses modulescode organizationreusability
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

named, default, and dynamic import
// math.js — named + default exports
export const add = (a, b) => a + b;
export const PI = 3.14159;
export default function multiply(a, b) { return a * b; }

// app.js — import them
import multiply, { add, PI } from "./math.js";
console.log(add(2, 3), PI, multiply(2, 4)); // 5 3.14159 8

// rename + namespace import
import { add as sum } from "./math.js";
import * as math from "./math.js";

// dynamic import for lazy code-splitting (returns a promise)
const { add: lazyAdd } = await import("./math.js");
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.