EasyFunctions📖 Theory Question

What is a pure function and why does it matter?

💡

Hint

Same input → same output, no side effects

Full Answer

A pure function: (1) always returns the same output for same inputs, (2) has zero side effects.

// Pure ✅
const add = (a, b) => a + b;

// Impure ❌ — modifies external state
let total = 0;
const addToTotal = (n) => { total += n; return total; };

Pure functions are predictable, testable, and cacheable. React expects components and reducers to be pure.

More Functions Questions

EasyWhat is the difference between call, apply, and bind?EasyHow do arrow functions differ from regular functions?EasyWhat are Higher-Order Functions (HOF)?EasyWhat is an IIFE (Immediately Invoked Function Expression) and when do you use it?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint