# getVar

## Description

Returns the value of a global variable.

## Input / Parameter

| Name    | Description                        | Input Type  | Default | Options | Required |
| ------- | ---------------------------------- | ----------- | ------- | ------- | -------- |
| var     | The name of the variable.          | String/Text | -       | -       | Yes      |
| default | The default value of the variable. | String/Text | -       | -       | No       |

## Output

| Description                                                                                          | Output Type |
| ---------------------------------------------------------------------------------------------------- | ----------- |
| Returns the value of the global variable if there is a value, returns the `default` value otherwise. | String/Text |

## Callback

N/A

## Video

## Example

### Steps

1. Drag the `getVar` function into the event flow panel. (\*Note: The `console` function is used here for ease of demostrating the output.)
2. Specify the variable name that you would like to access.

![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-a70e4a68c2af62a28dd0d0a8bdf2bd5a61050552%2FgetVar-step-1.png?alt=media)

### Result

| Variable exists                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Variable does not exist                                                                                                                                                                                                                                                                                                                          |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p>If the specified global variable has previously been set (see <a href="https://github.com/OrangeKloud/emobiq-documentation/blob/master/document/client/006-actions-and-visual-logic/action-reference/cordova/App/getVar/setvar/README.md"><code>setVar</code></a>), the function will return the variable's value: ("1.0.0" in this example)<br><img src="https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-89a7c4b93a41f40e1df9ee1d9b9960538d885ca9%2FgetVar-step-2.png?alt=media" alt=""></p> | <p>If the specified global variable does not exist, the function will return the value in <code>default</code>:<br><img src="https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-4fa7bbf40fc30da735e3d6d78a82b16a9dfdd7d8%2FgetVar-step-3.png?alt=media" alt=""></p> |

## Links

* See also [`setVar`](https://github.com/OrangeKloud/emobiq-documentation/blob/master/document/client/006-actions-and-visual-logic/action-reference/cordova/App/getVar/setvar/README.md)
