What is a pure function in functional programming?
A pure function is a function that has no side effects and always returns the same output for the same input. Side effects include modifying external variables, making API calls, or performing I/O operations. Pure functions are a fundamental concept in functional programming because they make code more predictable, testable, and easier to reason about. Since pure functions only depend on their inputs and don't modify external state, they can be safely composed, memoized, and parallelized. Higher-order functions in JavaScript are often designed to work with pure functions as callbacks for maximum composability and predictability.