# Functions

## Introduction

A **function** is a construct for providing advanced functionality inside of a [clause](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/clauses).  As in mathematics, a function typically accepts some sort of input, performs an operation, and returns a result.

For example, a hypothetical function could accept two numbers and return their sum.

For a list of available functions, visit the [function reference](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/functions).

## Anatomy of a function

In ESCL, all functions are comprised of two parts: a name in uppercase and an arguments [clause](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/clauses) wrapped in parenthesis.

{% hint style="info" %}
A function's arguments clause is processed just like any other clause, so it may contain [variables](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/variables), [string](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/string-resources) identifiers, [terms](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/terms), and even other functions.
{% endhint %}

In this example, the function's name is `LINK` and its arguments clause is `:myText, :myUrl`.

```javascript
LINK(:myText, :myUrl)
```

## Working with functions

A function may be included in a [clause](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/clauses), just like a [variable](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/variables) or [string](https://docs.elentra.org/ejs/1.3/guide/internationalization/escl/concepts/string-resources) identifier.  In fact, you can use them together:

```javascript
welcome_message: `Hello, { LINK(:linkText, :linkUrl) }, and welcome!`
```

Then, when we translate the string, we pass in some variable values:

```javascript
$translate('welcome_message', {
    linkText: 'John Doe',
    linkUrl: 'profile.php'
});
```

And that's it!  We've created a hyperlink directly in our string:

```markup
Hello, <a href="profile.php">John Doe</a>, and welcome!
```

## Nesting functions

Sometimes, you may want to call multiple functions on the same piece of text.  For this, you can nest multiple function calls, and they will be executed in order.

In this example, we want to create a link that is also bold:

```javascript
welcome_message: `Hello, { BOLD(LINK(:linkText, :linkUrl)) }, and welcome!`
```

Then, when we translate the string, we pass in some variable values:

```javascript
$translate('welcome_message', {
    linkText: 'John Doe',
    linkUrl: 'profile.php'
});
```

Voila!  We've used both functions together to provide a result that is bold and linked:

```markup
Hello, <strong><a href="profile.php">John Doe</a></strong>, and welcome!
```
