Net-informations.com
SiteMap  | About    

Pure functions Vs. Impure functions

Pure functions

Pure functions always returns the same result if the same arguments are passed in. It does not depend on any state, or data, change during a program's execution. It must only depend on its input arguments . They do not have any side effects like network or database calls and do not modify the arguments which are passed to them.

example

Impure functions

Any function that changes the internal state of one of its arguments or the value of some external variable is an impure function . They may have any side effects like network or database calls and it may modify the arguments which are passed to them.

example

Math.random() is an impure function; it changes the internal state of the Math object so you get different values on successive calls.









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.