# Variable

## Overview

The `ScriptVariable` class is used either in a global scope under solution or as a form variable within the Servoy environment. It allows for defining and managing variables with properties such as name, scope, and type. The class supports various functionalities, including setting and retrieving the variable’s name and scope with methods like `setName()` and `getScopeName()`. It also provides the ability to manage the variable's default value using `setDefaultValue()` and `getDefaultValue()`, along with calculating its initial value through the `getInitValue()` method.

The class handles the type of the variable, ensuring it is correctly set and validated with `setVariableType()` and `getVariableType()`. It can also generate string representations of the variable providing useful metadata like type and default value in an HTML format.

Additionally, `ScriptVariable` supports various annotations which are checked using methods like `isPrivate()`, `isPublic()`, and `isDeprecated()`. The class also includes functionality for handling custom properties, such as a keyword with `getKeyword()` and `setKeyword()`.

In essence, the `ScriptVariable` class offers a comprehensive solution for defining and managing variables in the Servoy environment, providing flexibility for visibility, scope, and customization.

## Properties Summarized

| Type                                                     | Name                          | Summary                                                                           |
| -------------------------------------------------------- | ----------------------------- | --------------------------------------------------------------------------------- |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [comment](#comment)           | Property for setting and getting the jsdoc text (comment) of the script variable. |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [defaultValue](#defaultvalue) | The default value of the variable.                                                |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [name](#name)                 | The name of the variable.                                                         |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [scopeName](#scopename)       | The name of the scope.                                                            |
| [Number](/reference/servoycore/dev-api/js-lib/number.md) | [variableType](#variabletype) | The type of the variable.                                                         |

## Properties Detailed

### comment

Property for setting and getting the jsdoc text (comment) of the script variable.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md) the value of the jsdoc text (comment) of the script variable

### defaultValue

The default value of the variable.

It is interpreted as a JS expression.

For form variables, setting this property via solutionModel requires the form instances to be destroyed (history.remove("formName")).\
If you want to use a default value for a newly created variable create the variable using the 3 parameter version newVariable(name,type,defaultValue).

For INTEGER variables it can be an integer constant, like 10 for example.\
For NUMBER variables it can be a real constant, like 22.41. For DATETIME variables it can be "now", or a JS expression like "new Date()". For TEXT variables it can be any string surrounded with quotes, like "'some text'".

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

### name

The name of the variable.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

### scopeName

The name of the scope.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

### variableType

The type of the variable. Can be one of: TEXT, INTEGER, NUMBER, DATETIME or MEDIA.

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/object-model/solution/variable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
