Loading Depth Study
Preparing your workspace
Modules allow developers to divide application code into separate files with explicit dependencies and exports.
As applications grow, keeping everything in one JavaScript file becomes difficult to maintain. ES modules allow code to be split into focused files. A module can export functions, objects, classes, or values, and another module can import exactly what it needs. Named exports are useful when a file provides multiple related values, while default exports can represent a main value from a module. Clear module boundaries make testing, reuse, and maintenance easier.
A learning platform might keep authentication logic, API functions, utility functions, and course calculations in separate modules.
export function calculateProgress(completed, total) {
if (total === 0) return 0;
return Math.round((completed / total) * 100);
}
// progress.js
import { calculateProgress } from './progress.js';
const result = calculateProgress(7, 10);
console.log(result);The imported function is used to calculate and print 70.