Created
January 6, 2017 15:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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