# 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](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4Nnmtk9_gFGWOddsf6%2Fuploads%2FsAx0QFIDB4D799CVtYzF%2Fnew_coding.gif?alt=media\&token=c660f079-eff4-4aba-89dd-3c5d46b0fdf0)

{% 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](https://readme.directual.com/scenarios/testing-and-debugging).
{% endhint %}

![Checking the expression providing an object with ID=1](https://3071851461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4Nnmtk9_gFGWOddsf6%2Fuploads%2F3FmZclSqqReV6f3Br0uq%2Fnew_coding_2.gif?alt=media\&token=fd9d8fc3-8750-4601-8890-2c2f923307e1)

### 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="../basics-of-template-system#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="tips-for-working-with-data">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.
