Partial Application
Fix some arguments and reuse functions.
Partial Application is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Partial Application?
Partial application means taking a function that needs several arguments and fixing some of them ahead of time, producing a new function that needs only the rest.
It lets you build specialized functions from general ones. A generic multiply(a, b) can become a specialized double(b) by fixing a = 2.
A Function With Many Arguments
Start with a general-purpose function. Here add takes three numbers. Often you call it again and again with the same first argument.
function add(a, b, c) {
return a + b + c;
}
console.log(add(1, 2, 3));
console.log(add(1, 10, 100));Fixing Arguments Manually
The simplest partial application is just a wrapper function that hard-codes one argument and forwards the rest.
function add(a, b, c) {
return a + b + c;
}
function addTen(b, c) {
return add(10, b, c);
}
console.log(addTen(2, 3));
console.log(addTen(20, 30));Partial Application With bind
Function.prototype.bind is built for this. Its first argument sets this; every argument after that is pre-filled from the left.
Pass null for this when you do not care about it.
function add(a, b, c) {
return a + b + c;
}
const addTen = add.bind(null, 10);
console.log(addTen(2, 3));
console.log(addTen(20, 30));Binding More Than One Argument
You can fix several leading arguments at once. The returned function takes whatever is left over.
function add(a, b, c) {
return a + b + c;
}
const addElevenAndTwo = add.bind(null, 11, 2);
console.log(addElevenAndTwo(7));
console.log(addElevenAndTwo(100));A Reusable partial Helper
You can write your own partial that captures preset arguments with the rest parameter and merges them with the later ones using spread.
function partial(fn, ...preset) {
return function (...later) {
return fn(...preset, ...later);
};
}
function greet(greeting, name) {
return greeting + ', ' + name + '!';
}
const sayHello = partial(greet, 'Hello');
console.log(sayHello('Ada'));
console.log(sayHello('Linus'));Specializing General Functions
Partial application shines when one general function spawns many small, readable specializations.
function multiply(a, b) {
return a * b;
}
const double = multiply.bind(null, 2);
const triple = multiply.bind(null, 3);
console.log(double(5));
console.log(triple(5));Partial Application With Arrays
Specialized functions read cleanly inside array methods like map.
function power(exponent, base) {
return Math.pow(base, exponent);
}
const square = power.bind(null, 2);
console.log([1, 2, 3, 4].map(square));Pre-filling Configuration
A common real-world use is fixing a configuration value, like a tax rate or a currency symbol, then reusing the result everywhere.
function format(symbol, amount) {
return symbol + amount.toFixed(2);
}
const usd = format.bind(null, '$');
const eur = format.bind(null, '\u20AC');
console.log(usd(9.5));
console.log(eur(9.5));Partial vs Default Parameters
Default parameters give a fallback when an argument is missing. Partial application locks in a value so the caller can no longer change it for that slot.
They solve different problems: defaults are optional, partials are fixed.
function log(level, message) {
return '[' + level + '] ' + message;
}
const error = log.bind(null, 'ERROR');
console.log(error('Disk full'));
console.log(error('Timeout'));Why Partial Application Matters
Partial application reduces repetition, names intent clearly, and is the foundation for currying. Whenever you keep passing the same first argument, consider fixing it once.
function between(min, max, value) {
return value >= min && value <= max;
}
const isPercentage = between.bind(null, 0, 100);
console.log(isPercentage(50));
console.log(isPercentage(150));Quick Check
What does fn.bind(null, 5) return?
Recap: Partial Application
You learned to fix arguments ahead of time:
- Manual wrappers hard-code an argument and forward the rest.
- bind(null, ...args) pre-fills arguments from the left.
- A custom
partialhelper uses rest and spread. - Partial application creates clear, reusable specializations and sets the stage for currying.
Frequently asked questions
Is the “Partial Application” lesson free?
Yes — the full text of “Partial Application” is free to read here on the web, and the JavaScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Partial Application”?
Fix some arguments and reuse functions. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Partial Application” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Partial Application
- Currying Functions
- Function Composition
- Building pipe and compose