What is partial application?
JavaScriptThe short answer
Partial application is when you fix some arguments of a function and return a new function that takes the remaining arguments. Instead of passing all arguments at once, you "pre-fill" some of them. This creates specialized versions of general functions.
How it works
function multiply(a, b) { return a * b;}// Partially apply the first argumentfunction double(b) { return multiply(2, b);}function triple(b) { return multiply(3, b);}double(5); // 10triple(5); // 15double and triple are partially applied versions of multiply — the first argument is fixed.
Using bind
Function.prototype.bind is a built-in way to do partial application:
function multiply(a, b) { return a * b;}const double = multiply.bind(null, 2);const triple = multiply.bind(null, 3);double(5); // 10triple(5); // 15The first argument to bind sets this (we use null since we do not need it). The remaining arguments are pre-filled.
A generic partial function
function partial(fn, ...presetArgs) { return function (...remainingArgs) { return fn(...presetArgs, ...remainingArgs); };}function add(a, b, c) { return a + b + c;}const add10 = partial(add, 10);add10(5, 3); // 18const add10and5 = partial(add, 10, 5);add10and5(3); // 18Practical examples
Creating API fetchers:
function fetchFromApi(baseUrl, endpoint) { return fetch(`${baseUrl}${endpoint}`).then((r) => r.json() );}const fetchFromGithub = partial( fetchFromApi, 'https://api.github.com');const fetchFromStripe = partial( fetchFromApi, 'https://api.stripe.com');fetchFromGithub('/users/octocat');fetchFromStripe('/v1/customers');Event handlers with extra data:
function handleClick(userId, event) { console.log(`User ${userId} clicked`, event);}<button onClick={partial(handleClick, user.id)}> Click</button>;Interview Tip
Show a simple example like double from multiply, then the bind approach. If the interviewer asks about the difference from currying, partial application fixes some arguments at once, while currying transforms a function to take arguments one at a time.
Why interviewers ask this
Partial application tests if you understand function composition and can create specialized functions from general ones. It is a common pattern in functional programming that shows up in real code — event handlers, API clients, and configuration.