A side effect in programming occurs when executing a function results in something else happening other than strictly performing the function and receiving the standard output. This might mean that a variable‘s value changes while being calculated in a function. Declarative programming languages rarely have side effects; the code is straightforward and does not detail every step needed to complete a function. If the objects they use are immutable, which in declarative programming they typically are, functions will behave the same each time they run, without having side effects in another part of the program.
A side effect often changes the state of the program itself, not just the local area in which it appears. This is sometimes known as a “global” change, when it changes the values of variables outside that particular function’s local area. Of course, for an application or computer program to work, it does need to allow modification through side effects: outputs sometimes must change. And databases will have many side effects as data changes and mutates. But there are benefits to purely functional programming as well.
Functional programming, which avoids side effects, is easier for developers to read and analyze. Pure functions (which have no side effects) perform the same calculation each time they are repeated, with no variation or side effect. Avoiding side effects in a program makes it more readable and reliable.