Declarative programming describes the result or logic you want without spelling out every control-flow step or state change used to produce it. It contrasts with imperative programming, where a program is a top-to-bottom sequence of statements that changes system state. Functional programming uses this style to separate program description from evaluation, making the main logic easier to inspect and alter without rewriting its internal steps. section 1.2
Square an array by describing the transformation
An imperative solution loops through an array and overwrites each item with its square. A declarative rewrite uses map with a squaring function: the code states that each number should be transformed, while map handles the traversal. Both produce the same squared array, but the latter keeps the desired operation separate from the iteration mechanics. section 1.2
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(
function(num) {
return Math.pow(num, 2); #1
});
//-> [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
This map expression names the transformation to apply to every number instead of exposing a loop, index, and assignment. section 1.2
Function chains extend the same idea to data processing. Operations such as map, filter, and reduce can be linked so that each step describes a transformation, selection, or aggregation of data. This removes many manual loops and shifts attention toward the output and the structure of the data. section 3.3 section 3.0
Select and format people
A chain can filter people born in 1903, map them to full names, and join the names into one string. Rather than managing a result array and loop conditions directly, the chain states the successive data operations: select matching people, extract names, then combine them. section 3.3
Declarative style works especially well with pure functions and function composition. Small functions can serve as reusable building blocks, while avoiding unnecessary changes to global state improves readability, testability, modularity, and maintainability. section 1.2 section 1.4














