Mark As Completed Discussion

Side effects

Side effects are observed "outside" a function and are not related to the return value from the function itself. For example, all I/O operations are considered to be side effects. The same multiply method that we saw above will become impure if we simply add a console.log() statement. Some of the common side effects are given below.

  • I/O operations (writing to the screen, writing to a file)
  • Network operations (writing to network)
  • Invoking other processes or functions that have side effects

But how can we build a useful application that doesn’t interact with the outside world? Without I/O operations, network operations, or invoking other processes or functions, how do we create value? It is a recommended best practice to keep functions as pure as possible and then move these operations to the edge of your application.