loading...

re: The beauty of Functional Programming VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Well, it is a pure function. What is wrong with accessing variables from function scope?

Because it is performing a side effect, by definition, can you write me a example using interation that you agree that is a impure function?

Sure

let result = 0

function myCount() {
  for (let i = 1; i < 10; i++) {
    result += i
  }
  return result
}

There is example of doing side effects by modifying outside scope, which as you stated, makes the function impure.

In your example you aren't accessing "outside" state

code of conduct - report abuse