# JavaScript The JavaScript brick runs your own code during the call: it reads and writes scenario variables and can use ready-made tools such as email, Google Sheets or a wait. Every text setting of this brick takes variables and contact fields, such as `{{contact.first_name}}`. Number, switch and list settings do not. See [Variables](https://docs.aiva.apifonica.com/guides/build/variables/). ![JavaScript editor](https://docs.aiva.apifonica.com/_astro/82193ea9f758ed75a6a48dfee83f876a.zFSGCYoF_Z1nuKCC.webp) ## When to use Logic that bricks alone cannot express: calculations, date formatting, parsing JSON, combining several values, sending an email or adding a row to a sheet. For a single API lookup, HTTP request needs no code. ## The handler The brick runs the default export. It must stay async and take no parameters: ``` export default async function handler() { const name = storage.get('customer_name'); storage.set('greeting', 'Hello, ' + name); return 'ok'; } ``` | Call | What it does | | ----------------------------- | ---------------------------------------------------------------------------- | | `storage.get('key')` | Reads a variable as a string; undefined when it is not set | | `storage.set('key', 'value')` | Writes a variable; objects are saved as JSON. System variables are read-only | | `storage.unpack('key')` | Reads and parses a variable: true, 42 and JSON strings become real values | | Dotted keys | Contact fields, such as `contact.address.index` | ## Settings and tools | Control | What it does | | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **Brick API** (**< >**) | Lists the calls above and ready-made tools: today’s date, sending an email over your SMTP server, adding a row to a Google Sheet, waiting before the next step | | **Generate code** (✨) | Writes the function from a plain-language description | | **Deploy and save** | Stores and deploys the code | ![Brick API reference](https://docs.aiva.apifonica.com/_astro/f85ddb98bdc64ffdbb267966ce9d7525.BI1eVllo_nDL4L.webp) ## Outputs | Output | When | | --------- | ------------------------------------------------------------ | | Processed | The function finished; what it `return`s is the brick result | | Error | The code threw an error (`throw`) or failed to run | `console.log` output shows up in Testing. ## Good practice - Keep the code short and fast: the caller waits while it runs. - Write results into variables and branch on them with Conditions. - Never write secrets into the code; keep them on the server you call. ## Related [HTTP request](https://docs.aiva.apifonica.com/guides/bricks/http-request/), [Variables (brick)](https://docs.aiva.apifonica.com/guides/bricks/variables-brick/), [Calling your systems](https://docs.aiva.apifonica.com/guides/build/calling-your-systems/)