> For the complete documentation index, see [llms.txt](https://readme.directual.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://readme.directual.com/template-system/evaluating-as-js-expression.md).

# Coding Mode (evaluating as a JS-expression)

You have the option to enable or disable JavaScript evaluation in scenario steps (ECMAScript 5.1):

![Turning On/Off JS evaluation in scenario steps](/files/bUM56uI6vlbM5wZawdRj)

{% hint style="warning" %}
Please note that if you enable this option and make a syntax mistake, the scenario will pause with an exception message.
{% endhint %}

### Checking expressions

You can verify the result of your expression by clicking the "Check the expression" link. You'll need to provide an object ID for validation.

{% hint style="info" %}
Don't mix "Check the expression" feature with [step testing](/scenarios/testing-and-debugging.md).
{% endhint %}

![Checking the expression providing an object with ID=1](/files/hawlzHd8vN510pmPKOs6)

### Examples of JavaScript expressions

| Expression                                                                                                                    | 🅾️ JS-interpreter is off | ✅ JS-interpreter is on                                                                                                                                     |
| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>{{a}} +1</code></p><p><code>// {{a}} = 3</code> </p>                                                                 | `3 + 1`                   | `4`                                                                                                                                                        |
| `Math.random()`                                                                                                               | `Math.random()`           | <p><code>0.4353</code></p><p><code>// some random value 0.0–1.0</code></p>                                                                                 |
| <p><code>Today +1 day</code></p><p>and <a href="/pages/-M4O1_yucP2cXfISMwkm#using-now-today-days">similar</a> expressions</p> | `Today +1 day`            | <p><code>2020-05-04T00:00:00.000Z</code></p><p><code>// today at 00:00</code></p>                                                                          |
| <p><code>'{{a}}'.length</code></p><p><code>// {{a}} == hello world</code></p>                                                 | `'hello world'.length`    | `12`                                                                                                                                                       |
| <p><code>'{{a}}'.length</code></p><p><code>// {{a}} == 1,-12,hello</code><br><code>(array type)</code></p>                    | `'1,12,hello'.length`     | <p><code>11</code></p><p><code>// Note! It evaluates as a string.</code></p><p>Learn how to <a href="/pages/-M4O4D-IKgGubEwJKlua">deal with arrays</a></p> |

{% hint style="info" %}
Don't forget to enclose `'{{fields}}'` in quotes if you want them to be processed as *strings*.
{% endhint %}

### Other resources

* [MDN JavaScript Guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide) - Get a high-level overview of fundamental JavaScript concepts.
* [Codecademy Introduction to JavaScript](https://www.codecademy.com/learn/introduction-to-javascript) - Learn JavaScript in this free online course with interactive lessons.
