PURE -IMPURE METHODS

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

function square(x){
return x*x

}

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

function getRandom(number)

{

a = Math.random()

if(a > 10){

return a

}

else{

return 10

}

}

This entry was posted in Basic. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *