Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
Created October 8, 2018 14:09
Show Gist options
  • Save devarajchidambaram/169097cbc3eba20380bf5a35a1d8186b to your computer and use it in GitHub Desktop.
Save devarajchidambaram/169097cbc3eba20380bf5a35a1d8186b to your computer and use it in GitHub Desktop.
Pure vs Impure function
/**
Characteristics of Pure Function:
The return value of the pure func­tions solely depends on its arguments Hence, if you call the pure func­tions with the same set of argu­ments, you will always get the same return values.
They do not have any side effects like net­work or data­base calls
They do not mod­ify the argu­ments which are passed to them
Char­ac­ter­isitcs of Impure functions
The return value of the impure func­tions does not solely depend on its arguments Hence, if you call the impure func­tions with the same set of argu­ments, you might get the dif­fer­ent return values For exam­ple, Math.random(), Date.now()
They may have any side effects like net­work or data­base calls
They may mod­ify the argu­ments which are passed to them
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment