Skip to content

Instantly share code, notes, and snippets.

@canattofilipe
Last active November 26, 2020 00:44
Show Gist options
  • Save canattofilipe/fcb683f5f46407c2801bfd3b160a1a32 to your computer and use it in GitHub Desktop.
Save canattofilipe/fcb683f5f46407c2801bfd3b160a1a32 to your computer and use it in GitHub Desktop.
// 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