Zum Hauptinhalt springen
IT Security NachrichtenUnderstanding Golden Ticket Attacks: Detection & Fix(03.10.2026 um 06:19 Uhr)
••••
Podcasts & Audio BriefingsMini-PCs im Test: stark wie nie, aber viele sind teuer | c’t uplink(03.10.2026 um 06:30 Uhr)
•
AI & KI NachrichtenStudents turn to lawyers to fight AI misconduct accusations(03.10.2026 um 06:00 Uhr)
•
AI & KI NachrichtenThe coming futures market in AI compute(03.10.2026 um 06:00 Uhr)
•••
Sicherheitslücken (CVE)CVE-2025-31995 | HCL MaxAI Workbench input validation (KB0124425)(03.10.2026 um 05:32 Uhr)
•
IT Security NachrichtenUnderstanding Golden Ticket Attacks: Detection & Fix(03.10.2026 um 06:19 Uhr)
••••
Podcasts & Audio BriefingsMini-PCs im Test: stark wie nie, aber viele sind teuer | c’t uplink(03.10.2026 um 06:30 Uhr)
•
AI & KI NachrichtenStudents turn to lawyers to fight AI misconduct accusations(03.10.2026 um 06:00 Uhr)
•
AI & KI NachrichtenThe coming futures market in AI compute(03.10.2026 um 06:00 Uhr)
•••
Sicherheitslücken (CVE)CVE-2025-31995 | HCL MaxAI Workbench input validation (KB0124425)(03.10.2026 um 05:32 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

JavaScript Module System Explained (with Examples)

As JavaScript applications grow, putting everything into one file quickly becomes unmanageable. That’s where the JavaScript module system comes in. Modules a…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

As JavaScript applications grow, putting everything into one file quickly becomes unmanageable.

That’s where the JavaScript module system comes in.



Modules allow us to split code into reusable files, control visibility, and load only what we need. Modern JavaScript uses ES Modules (ESM), which are now the standard for both browsers and Node.js.







Topics Covered





  • import and export

  • Named exports & imports

  • Default exports & imports

  • Aliasing

  • Namespace imports

  • Combined imports

  • Dynamic imports

  • Multiple dynamic imports using Promise.all







What Is a JavaScript Module?



A JavaScript module is simply a file that:




  • Has its own scope

  • Can export variables, functions, or classes

  • Can import values from other modules



To enable modules in the browser:




<script type="module" src="main.js"></script>












Named Export



Named exports allow you to export multiple values from a single file.






math.js






export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;












Named Import



When importing named exports, the names must match exactly.






main.js






import { add, subtract } from "./math.js";

console.log(add(5, 3)); // 8
console.log(subtract(5, 3)); // 2












Default Export



A module can have only one default export.

This is useful when a file exposes one main feature.






logger.js






export default function log(message) {
console.log("Log:", message);
}












Default Import



You can import a default export using any variable name.






main.js






import logger from "./logger.js";

logger("Hello Dev.to!");












Aliasing (Renaming Imports)



Aliasing helps avoid naming conflicts or improve readability.






math.js






export const multiply = (a, b) => a * b;









main.js






import { multiply as mul } from "./math.js";

console.log(mul(4, 5)); // 20












Namespace Import (* as)



If a module exports many values, you can import everything as an object.






math.js






export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;









main.js






import * as MathUtils from "./math.js";

console.log(MathUtils.add(10, 5)); // 15
console.log(MathUtils.subtract(10, 5)); // 5












Combined Import (Default + Named)



You can combine default and named imports in a single statement.






user.js






export default function getUser() {
return { name: "Rayan", role: "Developer" };
}

export const isAdmin = false;









main.js






import getUser, { isAdmin } from "./user.js";

console.log(getUser());
console.log(isAdmin);












Dynamic Import (import())



Dynamic imports load modules at runtime instead of at page load.



Common use cases:




  • Code splitting

  • Lazy loading

  • Performance optimization






math.js






export const add = (a, b) => a + b;









main.js






async function loadMath() {
const math = await import("./math.js");
console.log(math.add(2, 3)); // 5
}

loadMath();







⚠️ import() always returns a Promise.










Multiple Dynamic Imports Using Promise.all



To load multiple modules in parallel, use Promise.all.






math.js






export const add = (a, b) => a + b;









string.js






export const upper = (text) => text.toUpperCase();









main.js






async function loadModules() {
const [math, string] = await Promise.all([
import("./math.js"),
import("./string.js")
]);

console.log(math.add(3, 4)); // 7
console.log(string.upper("hello")); // HELLO
}

loadModules();












Key Rules to Remember




  • One file can have multiple named exports

  • One file can have only one default export

  • Named imports must match export names

  • Default imports can be renamed freely

  • Dynamic imports always return a Promise









Final Thoughts



The JavaScript module system is the foundation of modern development.

Frameworks like React, Vue, and Node.js rely heavily on it.



Once you master import and export, your code becomes:




  • Easier to maintain

  • More scalable

  • Better organized



Happy coding 🚀

🔍 CTI & Forensik

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar · Exploit-Belege
IoC Intelligence
1 Indikatoren · Defanged · STIX 2.1
dev[.]to
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
2 Knoten · 1 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten JavaScript Module System Explained (with Examples)

Thematisch verwandte Begriffe: JavaScript, Module, System, Explained · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag