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

Prepare · Practice · Crack

What is a pure function and why does it matter?

Quick answer

A function that returns the same output for the same input and causes no side effects.

In detail

Pure functions don't mutate external state, do I/O, or depend on anything but their arguments. They're predictable, trivially testable, cacheable (memoizable), and are required for correct change-detection in React/Redux, where you produce new values instead of mutating.

// impure — mutates input
const addBad = (arr, x) => { arr.push(x); return arr; };
// pure — returns a new array
const add = (arr, x) => [...arr, x];

Why interviewers ask this: Signals maturity around state management and testing.

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 →