function makeAdder(n) {
return x => x + n
}
const add5 = makeAdder(5)
add5(3) // β 8
add5(10) // β 15Factory functions use closures to capture a preset value, producing specialized functions without repeating configuration.
Create a factory function that produces functions with preset behavior.
Challenge: Create a makeAdder(n) function that returns a function. The returned function takes a value and returns the sum of the preset value and the argument.
Example:
const add5 = makeAdder(5)
add5(3) // 8
add5(10) // 15