Functional programming (FP) organizes code around pure functions and immutable data. Functions take inputs, return outputs, and don't modify external state. This makes code predictable, testable, and easier to reason about. JavaScript, Python, and TypeScript all support FP patterns.

How Functional Programming Works

Imperative (OOP): loop through users, mutate a running total. Functional: users.filter(u => u.active).map(u => u.balance).reduce((sum, b) => sum + b, 0). No mutation, no loops, each step is a pure transformation. The result is the same, but the functional version is more declarative and composable.

Key FP concepts in practice: map/filter/reduce for collections, immutable state in React/Redux, pure functions for testing (same input → same output), higher-order functions (functions that take/return functions).

Key Concepts

  • Pure Functions — Same input always produces the same output — no side effects, no external state
  • Immutability — Data is never modified — create new copies instead of mutating existing data
  • Higher-Order Functions — Functions that take functions as arguments or return functions — map, filter, reduce
  • Composition — Build complex behavior by combining simple functions — pipe(parse, validate, transform)(data)

Frequently Asked Questions

Do I need to learn Haskell for FP?

No. JavaScript, TypeScript, and Python support FP patterns. Learn map/filter/reduce, pure functions, and immutability in the language you already use.

FP vs OOP — which is better?

Neither. Use FP for data transformations and stateless logic. Use OOP for domain modeling and encapsulation. Modern code mixes both freely.