Lesson 2 — Functions & modules
Small reusable pieces
A module is a file that shares some of its functions with other files. In Node you write module.exports = { area } in one file and const { area } = require("./geometry") in another. Here everything lives in one file, so we model a module as an object holding functions.
const geometry = { area: (w, h) => w * h };
geometry.area(3, 4); // 12
Note: this playground runs JavaScript in your browser, not in real Node, so Node-only tools (like fs or http) are not available. The exercise is a small plain-JS simulation of the Node idea.
Why it matters: splitting code into modules keeps each file small and lets you reuse it everywhere.
Add a perimeter(w, h) function to the geometry module (2 * (w + h)) and log both results.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.