Functional programming treats a program as a flow from input through functions to output. Rather than coordinating work through changing variables and shared objects, it abstracts data operations and control flow into functions, aiming to avoid side effects and reduce state mutation. section 1.2 section 1.0
The practical goal is simpler code under growth: small independent functions are easier to reason about, test, reuse, and combine. A function is most dependable when its result depends only on its inputs instead of external state that may change between calls. section 1.1 section 1.2
Replace a changing counter with an explicit input
An imperative increment function reads and updates an outside counter, so successive calls depend on hidden history. A functional version instead accepts counter and returns counter + 1. The state is visible at the call boundary, and the function leaves no external value changed. section 1.2
Figure 1.3. The process of decomposing breaks showStudent into smaller parts. These subtasks are independent and simpler to understand, so that when combined, they help solve the bigger picture.
Breaking student display into lookup, formatting, and DOM-update steps shows the central move: decompose one mixed task into smaller functions, then combine them. section 1.3
This style works through a few reinforcing habits:
- Decompose a large task until each function has one clear purpose, ideally as a simple independent unit of work. section 1.3
- Compose compatible functions so one function’s output becomes the next function’s input, forming a reusable pipeline. section 1.3 section 4.5
- Process collections with fluent chains such as filter, map, and reduce instead of manually tracking loop variables and totals. section 1.3 section 1.4
- Separate unavoidable effects, such as database access or DOM updates, from data lookup and formatting where possible. section 1.2
Functional code is declarative: it emphasizes what data transformation should happen rather than the step-by-step mutation used to achieve it. Composition can also be written point-free, creating functions without naming their arguments; that can raise abstraction, but overuse can obscure a program. section 1.4 section 4.5
Turn enrollment records into an average
Instead of a loop that updates totalGrades and totalStudentsFound, a chain filters students enrolled more than once, selects grades, and computes their average. Each operation describes one transformation, while the chain carries the data through the calculation. section 1.3
Statelessness is a design direction, not a claim that applications never interact with storage, events, or the DOM. Functional techniques reduce the complexity those interactions introduce by keeping more of the program in predictable function transformations; reactive streams can handle event-driven input. section 1.0 section 1.3


















