> For the complete documentation index, see [llms.txt](https://edsonha.gitbook.io/my-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edsonha.gitbook.io/my-gitbook/object-oriented-programming-oop/functional-programming-fp/idempotent.md).

# Idempotent

Idempotent - a function that for the same input gives the same output and can have side effects to outside function world. VS pure function - a function that for the same input gives the same output without any side effects. So, idempotent without side effect = pure function. The idea of impotence is a function that always returns or does what we expected to do (predictable). It is used in API - given a set of parameter, it will always return the same value, although it is not pure and communicating with the outside world.

```javascript
function notIdempotent(num) {
  return Math.random(num);
}

function goodIdempotent(num) {
  console.log(num);
}
```
