# Local variables

Variables lets us assign data to a named key, which can then later be retrieved or changed.

* You can use **the** `Set Variable` node to assign a value to a **variable name**.
* And **get** the value of a variable using the `Get Variable` node.

<figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2FZXcy2D19QoSs0kWBl5d4%2Fimage.png?alt=media&#x26;token=ff8e59de-9545-4a1d-9b3f-c1fd137481e2" alt=""><figcaption></figcaption></figure>

## Map outputs automatically to local variables

<figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2F4p0olp4ZP1Q7FfPKi5wM%2Fimage.png?alt=media&#x26;token=0f8b90cc-faa1-4193-a5e4-a2c4746544a3" alt=""><figcaption></figcaption></figure>

Any function output can be automatically mapped to a local variable (meaning it automatically sets a local variable to the value of that output after it has been called). You can do this by simply clicking the output property on the function instance. You can then also edit the name if you want to set a different variable.

## Mutability

Local variables can be either mutable or immutable (the default). This is a mechanism that helps prevent bugs where two nodes make changes to the same variable without you explicitly declaring that this is OK. You can make a variable mutable by clicking the "mut" toggle button on a setter or getter node, or from a dropdown on the function output property if you are using the [automatic mapping](#map-outputs-automatically-to-local-variables).

{% hint style="warning" %}
Note that all places that sets a variable must declare it "mutable" if there is more than one place that sets.
{% endhint %}

<figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2Fwuui7Yn9qjPrqafd56jP%2Fimage.png?alt=media&#x26;token=60f7521a-54db-4dff-930e-66aece590b7c" alt=""><figcaption></figcaption></figure>

<div align="center" data-full-width="true"><figure><img src="https://1896308808-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdFpuRAnTVYgmlCXLLou%2Fuploads%2FvSJiSaXAClvLFdoUJyno%2Fimage.png?alt=media&#x26;token=71ec17c9-5834-4897-b8f1-2fc3e34fb21b" alt="" width="563"><figcaption></figcaption></figure></div>

## What does *local* mean?

Variables being **local** means changing a variable in one module or function doesn't affect a variable with the same name in a different module or function. This means you don't have to worry about the same variable already being in use in a different part of your application; you only have to look in the current function/module.

{% hint style="warning" %}
Note that a **variables** value does not persist between [processes](https://docs.midio.com/midio-docs/reference/overview/processes).
{% endhint %}
