Skip to content

Instantly share code, notes, and snippets.

@alexnault
Created March 24, 2019 01:31
Show Gist options
  • Save alexnault/11821fbf7c160daff07d15e1c46502dd to your computer and use it in GitHub Desktop.
Save alexnault/11821fbf7c160daff07d15e1c46502dd to your computer and use it in GitHub Desktop.
Pure function example with JavaScript
// impure (using side effect instead of return value)
function addTaco(array) {
array.push("taco");
}
// impure (using shared variable instead of argument)
function addTaco() {
return [...globalArray, "taco"];
}
// pure
function addTaco(array) {
return [...array, "taco"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment