Skip to content

Instantly share code, notes, and snippets.

@newmanbrad
Created January 6, 2017 15:47
Show Gist options
  • Save newmanbrad/7b8f0a44d3f45b93e3ec06c3689c9c38 to your computer and use it in GitHub Desktop.
Save newmanbrad/7b8f0a44d3f45b93e3ec06c3689c9c38 to your computer and use it in GitHub Desktop.
An example of a side effect that makes a program hard to reason about
// The result of the 'exampleFunction' is difficult to reason about.
let n = 10;
// function with a side effect
const exampleFunction = function ( i ) {
return n = n + i;
};
exampleFunction( 2 ); // result is 12
// if we run the function again..
exampleFunction( 2 ); // result is 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment