Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Functional programming

Функциональное программирование

This style of programming builds software by combining functions that turn inputs into outputs. Instead of editing existing data in place, those functions typically return new values.

Also known as: ФП, FP

What functional programming means

Functional programming (FP) treats computation as a series of transformations. Suppose a checkout page needs a subtotal: take the items in the cart, work out the cost of each line, and add those costs together. Each step takes a value and produces another value. Connecting steps so that one function's output becomes another's input is called function composition.

The building blocks

  • Pure functions produce the same result for the same inputs and have no observable side effects. A pricing function that reads the current time to decide whether a sale is active has a hidden dependency. Pass the time in as an argument and you can test the sale cutoff without changing the system clock.
  • Immutability means a value isn't changed after it's created. To change an item's quantity, return an updated version rather than editing the original. This makes it possible to keep and compare old versions. It doesn't require copying everything: unchanged parts can be shared as long as they aren't mutated.
  • Higher-order functions take functions as arguments or return them. For instance, map handles traversing a collection while your callback specifies how to transform each element.

Example: subtotal in cents

function subtotal(items) {
  return items
    .map(item => item.unitPriceCents * item.quantity)
    .reduce((total, lineCost) => total + lineCost, 0);
}

map produces a list of line costs, and reduce adds them into a single number. Two items at 300 cents each and one at 150 cents give a subtotal of 750. The initial 0 makes the empty-cart result explicit. The function doesn't edit the cart, fetch prices, or charge a card, so a unit test only needs to supply the items and check the number it gets back.

Where it helps and what it doesn't guarantee

Functional techniques work well for data processing, pricing rules, and UI state updates. You don't need a dedicated functional language to use them. A JavaScript service can fetch data, pass it to a pure calculation, and save the result. The external operations still happen; separating them from the calculation makes both parts easier to reason about.

A chain of array methods isn't automatically functional: a callback can still mutate an input object. Conversely, a loop that updates a local accumulator can live inside a pure function because callers cannot observe that internal mutation. In the subtotal example, map allocates an intermediate array; a single pass can calculate the same result without that allocation.

How it comes up in interviews

You may be asked to rewrite a function that changes its input or reads from shared state. Explain which values must become explicit inputs, what the new function returns, and where effects such as writing to a database should happen. If you're updating nested data, check whether a shallow copy leaves the old and new versions sharing the object you intend to change.