Your 'adding' example of a pure function is kind of a pure function, but not for the reason you think it is. Your function does not have a return, so is implicitly returning undefined - so, yes, it always returns the same thing given the same inputs - but in this case, that 'same thing' is always undefined.
Another reason that it isn't really 'pure' is that it completely relies on outside state - i.e. console.log - which it has no control over - someone could easily redefine console.log to have different behaviour.
Also, pure functions should try to avoid side effects (modifying state outside of the function) - console.log is clearly a side effect
Your 'adding' example of a pure function is kind of a pure function, but not for the reason you think it is. Your function does not have a
return, so is implicitly returningundefined- so, yes, it always returns the same thing given the same inputs - but in this case, that 'same thing' is alwaysundefined.Another reason that it isn't really 'pure' is that it completely relies on outside state - i.e.
console.log- which it has no control over - someone could easily redefineconsole.logto have different behaviour.Also, pure functions should try to avoid side effects (modifying state outside of the function) -
console.logis clearly a side effectThanks a lot for your note, I will rewrite this example.