ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What are higher-order functions? Give examples.

Quick answer

Functions that take or return other functions — the basis of map/filter/reduce, event handlers and middleware.

In detail

Because functions are first-class values, they can be passed and returned. A higher-order function does one or both. `map`, `filter`, `reduce`, `setTimeout`, and decorators (a function that wraps another to add logging/caching) are all examples.

1const withLog = fn => (...a) => { console.log(a); return fn(...a); };
2const add = (x, y) => x + y;
3withLog(add)(2, 3); // logs [2,3], returns 5
4
5const times = n => x => x * n;
6times(3)(10); // 30

Why interviewers ask this: Tests functional thinking, central to modern JS/React.

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →