Created
March 24, 2019 01:31
-
-
Save alexnault/11821fbf7c160daff07d15e1c46502dd to your computer and use it in GitHub Desktop.
Pure function example with JavaScript
This file contains hidden or 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
// 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