Lesson 8 / 11

Modules and What’s Next

Splitting code into modules

// math.js
export function add(a, b) {
  return a + b;
}

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

export makes a function, variable, or class available to other files; import brings it into whichever file needs it. This is how real projects stay organized across dozens or hundreds of files instead of living in one giant script — each module handles one clear responsibility.

Default vs named exports

// a file can have one default export:
export default function Course() { /* ... */ }
import Course from "./course.js";

// and any number of named exports:
export const MAX_LESSONS = 20;
import { MAX_LESSONS } from "./constants.js";

Where to go from here

  • Frontend frameworks — React, Vue, or Svelte build directly on everything in this course, especially functions, arrays/objects, and the DOM lesson
  • Node.js — the same language you just learned, running servers instead of browsers, with access to the file system and databases
  • TypeScript — JavaScript with optional static types layered on top, increasingly common on larger teams and projects

Onward to the advanced lessons

You now know variables, functions, arrays/objects, the DOM, and async code — enough to build interactive pages and read most JavaScript codebases. The next three lessons go deeper into how the language actually works under the hood: closures, classes, and handling errors like a professional.