← Todas las publicaciones
post3 de abril de 2026
¿Qué es una Función Pura?
#javascript#functional#pure-functions#interview
What makes a function 'pure' in JavaScript? Why does purity matter?
A pure function follows two rules: 1. **Deterministic**: same inputs always produce same output 2. **No side effects**: doesn't modify anything outside its own scope ```js // Pure const add = (a, b) => a + b; const double = arr => arr.map(x => x * 2); // returns new array // Impure — modifies external state let total = 0; const addToTotal = n => total += n; // side effect! // Impure — reads external mutable state const getTime = () => Date.now(); // non-deterministic ``` Why it matters: pure functions are testable (no mocks needed), cacheable (memoizable), and safe to run in parallel.