# Imperative vs Declarative

#### Imperative:

It is a code that says the machine, what to do and how to do.

```javascript
Ex:
for (let i = 0; i < 1000; i++) {
    console.log(i);
}
```

#### Declarative:

It is a code that says the machine, what to do and what should happen. It doesn't tell how to do. `Ex: Humans`

```javascript
Ex:
[1, 2, 3].forEach(item => console.log(item));
```

Functional programming is mostly be a declarative, we don't say how to do.


---

# 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://javascript-1.gitbook.io/javascript/fp/imperative-vs-declarative.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.
