01 / 09

What is currying?

Currying is a functional programming technique where a function that takes multiple arguments is transformed into a sequence of functions, each taking a single argument.

  1. 1

    Currying in JavaScript transforms a function with multiple arguments into a nested series of functions, each taking a single argument.

  2. 2

    The parent function takes the first provided argument and returns the function that takes the next argument and this keeps on repeating till the number of arguments ends. The function that receives the last argument returns the expected result.

Difficulty: 5/10
Topics: partial application, function composition, higher-order functions

Scenario Questions

0-2 years experience
  1. 1

    We have a simple function add(a, b) that returns a + b. How would you rewrite it using currying so that you can call add(2)(3)?

  2. 2

    If you have a curried function multiply(a)(b) and you call multiply(5) without the second argument, what does it return and why?

2-5 years experience
  1. 1

    Our team is building a form validation library where each validator is a curried function that takes a config object first, then the value to validate. A bug appears where the config is shared across calls. What could be causing this and how would you fix it?

  2. 2

    You need to compose three curried functions to process user input in a pipeline. How would you wire them together, and what trade‑offs does currying introduce compared to passing all arguments at once?

5-8 years experience
  1. 1

    We're refactoring a large codebase to use a functional utility library that heavily relies on curried functions for API calls. What performance or memory considerations should we keep in mind, and how would you mitigate potential issues?

  2. 2

    Design a generic curried fetch wrapper that allows partial application of URL, options, and then a callback. How would you ensure type safety and avoid leaking state across requests in a high‑traffic service?

8+ years experience
  1. 1

    Our organization wants to standardize a curried API across multiple microservices to improve composability. What architectural guidelines would you set, and how would you handle backward compatibility with existing non‑curried callers?

  2. 2

    Consider a legacy monolithic JavaScript app where many functions are not curried. Propose a migration strategy to introduce currying without breaking downstream teams, including testing and rollout plans.

Follow-up Questions

  • Can you compare currying to partial application and tell me when you'd choose one over the other?
  • How does JavaScript's handling of this and closures affect a curried function's behavior?
  • What impact does currying have on stack traces and debugging in production?