DEV Community

Discussion on: The beauty of Functional Programming

 
ivanpierre profile image
Ivan Pierre • Edited

result is an external state, initialized outside the function. myCount() will give a different response, every time you call it. There's a side effect on i inside the loop.
That's anything except a pure function.

Pure function:

  • Its return value is the same for the same arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams from I/O devices).
  • Its evaluation has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams).