Code you can trust
A pure function always returns the same output for the same input and changes nothing outside itself. Pure code is easy to test, safe to reuse, and the backbone of tools like React and Redux.
Pure vs impure
let total = 0;
function addImpure(n) {
total += n;
return total;
}
const add = (a, b) => a + b;
console.log(addImpure(5), addImpure(5));
console.log(add(5, 5), add(5, 5));