map returns a new array (use for transformation). forEach returns undefined (use for side effects). Do not use map if you do not need the return value; it wastes memory.
Functional Programming Interview Questions in JavaScript
What is the difference between map and forEach in JavaScript?
The answer
More FAQs in Functional Programming Interview Questions in JavaScript
A function that given the same input always returns the same output and has no side effects. It does not modify external state or read mutable external state. Pure functions are easy to test and reason about.
Return a function that applies the given functions right to left using reduceRight: return (x) => fns.reduceRight((acc, fn) => fn(acc), x). compose(f, g)(x) = f(g(x)).
Anything that interacts with the outside world: modifying external state, I/O, network calls, DOM manipulation, console.log, Math.random, Date.now. Pure functions have no side effects.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.