# 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);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://edsonha.gitbook.io/my-gitbook/object-oriented-programming-oop/functional-programming-fp/idempotent.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
