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
function getSquare(x) { return x * x; }

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
function getSquare(items) { var len = items.length; for (var i = 0; i < len; i++) { items[i] = items[i] * items[i]; } return items; }
Math.random() is an impure function; it changes the internal state of the Math object so you get different values on successive calls.