Side Effects
A side effect is any secondary effect or reaction that comes from an action we take. Side effects can be either good or bad, but are generally unintended. In functional programming, side effects are any state change that can be seen outside of a function call, with the exception of the function return value. According to the rules of functional programming, functions are not allowed to modify any states outside of the function. If the function modifies a state, intentionally or unintentionally, this is considered a side effect because it breaks the tenets of functional programming.
Side effects are bad because they make a program more complex. As discussed earlier, shared states increase program complexity. Side effects in functions modify shared states and therefore increase complexity. Side effects, intentional or otherwise, can make code much harder to test and debug. The following list shows a simple breakdown of the most common causes of side effects in JavaScript:
Modifying...