BeginnerCoder

Lesson 21 — Closure factories

Functions that make functions

A factory is a function that builds and returns another function, set up with some value. adder(10) returns a new function that adds 10 to whatever you give it — the 10 is remembered by closure.

const add10 = adder(10);
add10(5);   // 15

Why it matters: you can create many specialised helpers (tax calculators, formatters, validators) from one template.

Want it another way?
Task

Write multiplier(m) that returns (x) => x * m, then use it to make double and triple.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with JavaScript Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.