Sikau

JavaScript · Day 57 · about 30 min

Modules and classes

Splitting code and blueprints.

Organising bigger programs

As programs grow, two tools keep them tidy: modules split code into separate files, and classes are blueprints for making many similar objects.

Modules: export and import

A module is a file that shares some of its code with export. Other files bring it in with import.

// file: money.js
export function addTax(amount) {
  return amount * 1.13;
}

// file: app.js
import { addTax } from "./money.js";
console.log(addTax(100));

The rest of this lesson

  • Classes: blueprintsexplain
  • Classes in practiceexplain
  • Predict the outputpredict
  • Two objects, one classpredict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript