---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.3
alternate:
  - https://divkit.tech/docs/en/concepts/user-functions.md
  - https://divkit.tech/docs/ru/concepts/user-functions.md
---
> **Documentation Index:** Fetch the complete configuration index at https://divkit.tech/docs/en/llms.txt

# User-defined functions

In addition to [built-in functions](https://divkit.tech/docs/en/concepts/functions.md), you can declare your own.

User-defined functions are declared in the `functions` block. You cannot use [variables](https://divkit.tech/docs/en/concepts/variables.md) in them: you can only pass their values as function arguments. If your function name matches the name of a built-in function, your function will take priority.

Functions can be declared in nested elements. If the name and arguments of several user-defined functions match, the function closest to the call point will take priority.

## Field values

{% cut "Example of function declaration" %}

```
"functions": [
  {
    "name": "increment",
    "body": "@{value + 1}",
    "return_type": "integer",
    "arguments": [
      {
        "name": "value",
        "type": "integer"
      }
    ]
  }
]
```

The declared function returns the passed argument `"value"` increased by 1.

{% endcut %}

When declaring a function, you need to fill in the following fields:

* `"name"` — name;

* `"body"` — function body;

* `"return_type"` — type of returned data;

* `"arguments"` — list of function arguments. Each argument corresponds to a pair of `"name"` (name) and `"type"` (type).

{% cut "View an interactive example" %}

<iframe src="https://yastatic.net/s3/home/divkit/docs/1.0.8/index.html?url=https://yastatic.net/s3/home/divkit/doc_samples/common/user-functions_1.json" width="700" height="500" frameborder="1"></iframe>

{% endcut %}
