Currying — JS Technical Interview Questions & Answers

Transforming f(a,b,c) into f(a)(b)(c).

Currying

  • Currying (js) is a JS topic. In plain words you use it for a short Currying js example in a script in the browser. Don’t start with a slogan — start with that picture.
  • Smallest example: the smallest Currying js example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Currying (js).
  • From the example next to this theory: Transforming f(a,b,c) into f(a)(b)(c).
  • Trap: only saying “Currying js” with no example. Fix that before you talk about advanced JS.
  • Viva: what is Currying (js)? Then show the smallest Currying js example you can type. Then name the trap.

Technical Interview Tip: What is Currying (js)? Show this: the smallest Currying js example you can type. Trap: only saying “Currying js” with no example.

Code Examples for Currying

Currying — working example

function makeCounter() {
  let n = 0;
  return function () {
    n += 1;
    return n;
  };
}
const next = makeCounter();
console.log(next(), next(), next()); // 1 2 3

function makeAdder(x) {
  return (y) => x + y;
}
console.log(makeAdder(5)(3));

Currying — a closure remembers variables from its outer scope after that scope finished.

How to Explain Currying to an Interviewer

What is Currying (js)?

Used for a short Currying js example a script in the browser Not just the heading

Give one small example of Currying (js).

the smallest Currying js example you can type Transforming f(a,b,c) into f(a)(b)(c)

What mistake do beginners make with Currying (js)?

only saying “Currying js” with no example Show the fix

Where do you use Currying (js)?

a script in the browser a short Currying js example