re: Practical Functional Programming in JavaScript - Side Effects and Purity VIEW POST


A function's side effect is a modification of some kind of state beyond a function's control

It's not about being within control -- it's about reachability.

An effect doesn't exist for things which cannot be affected by it.

So in some cases we might consider logging output not to be a side-effect, if the log output is unreachable by that system.

Things like modifying local variables are fine, providing they do not escape, say by lexical closure.

They're fine because the changes to those variables cannot escape -- it makes the inside of the procedure clearly a procedure, but it doesn't affect the procedure's implementation of a pure function from the outside.


Thank you! I think escape (e.g. via closure) is a good way to put it. I've amended my use of the word control to the word reach, for clarity.

Code of Conduct Report abuse