Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 437 Bytes

pureFunctions.md

File metadata and controls

20 lines (16 loc) · 437 Bytes

Pure functions

A pure function is a function that always returns the same result when given the same arguments, without side effects.

Example:

function double(x){
  return x * 2;
}
// Will always return 4 when x is 2.
// Will always return 8 when x is 4, etc...
function randomise(y){
  return y * Math.random();
}
// Not a pure function because Math.random() always returns a different number.