×

javascript · level 3 · unit 4 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A is a file that shares only what it exports.

Real projects have hundreds of files. Each file is a module: its variables are private to that file, like the closures in unit 1. Writing before a function shares it, and another file writes to use it.

Gwecode runs one file at a time, so these lessons use a stand-in: an , a function wrapped in brackets and called the moment it is made. It runs once and returns what the module would export. Same idea: private inside, a few chosen names shared.

const tax = (() => {
  const rate = 0.2;
  function addVat(price) { return price + price * rate; }
  return { addVat };
})();
console.log(tax.addVat(50));
console.log(tax.rate);

In a real tax.js you would write export function addVat(price) { } and leave out the wrapper.