what is the difference between pure and impure function
Answers
Answered by
88
Pure function
1.The return value of the pure functions solely depends on its arguments Hence, if you call the pure functions with the same set of arguments, you will always get the same return values.
They do not have any side effects like network or database callsThey do not modify the arguments which are passed to them
Impure function
The return value of the impure functions does not solely depend on its arguments Hence, if you call the impure functions with the same set of arguments, you might get the different return values For example, Math.random(), Date.now()They may have any side effects like network or database callsThey may modify the arguments which are passed to them
1.The return value of the pure functions solely depends on its arguments Hence, if you call the pure functions with the same set of arguments, you will always get the same return values.
They do not have any side effects like network or database callsThey do not modify the arguments which are passed to them
Impure function
The return value of the impure functions does not solely depend on its arguments Hence, if you call the impure functions with the same set of arguments, you might get the different return values For example, Math.random(), Date.now()They may have any side effects like network or database callsThey may modify the arguments which are passed to them
DebrajKayal:
thank you but you have totally copied it from Quora!!
Answered by
59
Pure function takes place in Call by Value
Impure function takes place in Call by Reference
In pure function it doesn't modify the external variable/data outside the scope and results the same output given in the same input.
In impure function it mutates data/variable outside it's lexical scope Hope this helps..
Impure function takes place in Call by Reference
In pure function it doesn't modify the external variable/data outside the scope and results the same output given in the same input.
In impure function it mutates data/variable outside it's lexical scope Hope this helps..
Similar questions
Math,
7 months ago
Math,
7 months ago
Hindi,
7 months ago
English,
1 year ago
Psychology,
1 year ago