BeginnerCoder

Lesson 21 — Currying

One argument at a time

Currying turns a function that takes two arguments, f(a, b), into a function that takes one and returns another: f(a)(b). The first call "remembers" a through a closure. That lets you make specialised helpers from a general one.

const add = (a) => (b) => a + b;
const addTen = add(10);
console.log(addTen(5)); // 15

Why it matters: this style is everywhere in functional code and libraries (event handlers, configured validators, Redux middleware).

Want it another way?
Task

Rewrite multiply so multiply(3)(4) prints 12 and triple(10) prints 30.

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 Intermediate

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.