Last active
November 26, 2020 00:44
-
-
Save canattofilipe/fcb683f5f46407c2801bfd3b160a1a32 to your computer and use it in GitHub Desktop.
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
// A pure function is a function that the returned value | |
// is determined ONLY by the input values | |
// without side effects (change things out of function scope) | |
const PI = 3.14; | |
// example of impure function (PI is a external thing) | |
function circleArea(radius) { | |
return radius * radius * PI; | |
} | |
// example of pure function | |
function circleAreaPure(radius, pi) { | |
return radius * radius * pi; | |
} | |
console.log(circleArea(10)); | |
console.log(circleAreaPure(10, 3.14)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment