Closure
Function som "fångar" variables från sin lexical scope. function counter() { let n = 0; return () => ++n; } — returned function har access till n även efter parent returned. Standard i moderna språk: JS, Python, Ruby, Go, Rust.
Practical use: callbacks med captured-state, function-factories, partial-application, encapsulation utan classes. JavaScript: enables IIFE-pattern (Immediately Invoked Function Expression). Python: nested-functions med nonlocal-keyword för mutating captured-vars. Memory-consideration: closure håller reference till captured-scope → potential memory-leaks om captures stora-objekt. Rust: closures är types (Fn, FnMut, FnOnce) — explicit ownership-semantik. Static-typed-functional (Haskell, OCaml): closures är core-konstrukt, allt builder kring dem.