Computer Science, asked by DebrajKayal, 1 year ago

what is the difference between pure and impure function

Answers

Answered by ridhima29
88
Pure function

1.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 callsThey do not mod­ify the argu­ments which are passed to them

Impure function

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 callsThey may mod­ify the argu­ments which are passed to them

DebrajKayal: thank you but you have totally copied it from Quora!!
ridhima29: if you know this u could have too copied from quora
Answered by Lazarus
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..


DebrajKayal: thank you Sohame
Lazarus: hahaaa I'm not Soham!!
DebrajKayal: who are you?
Lazarus: I'm Saswata
Lazarus: Hahaaa Kohli one
Similar questions