|Home | Tutorial | Classes | Functions | QSA Workbench | Language | Qt API | QSA Articles | Qt Script for Applications |

[Prev: Qt Script Language Concepts] [Home] [Next: Classes and Methods]

### Identifiers, Variables and Constants

Qt Script identifiers match the regex pattern [_A-Za-z][_A-Za-z0-9]*. Identifiers are used for variables, constants, class names, function names and labels.

ECMAScript reserves some words which are valid identifiers for its own use. See the Built-in Functions and Operators chapter for the complete list.

Variables are declared using the var keyword:

        var a;               // undefined
        var c = "foliage";   // the string "foliage"
        x = 1;               // global variable

If a variable is assigned to without being declared, it is automatically declared as a global variable. Using global variables can make your code difficult to debug and maintain and is not recommended.

Constants are declared using the const keyword:

        const x = "Willow";
        const y = 42;

Constants must be defined at the point of declaration, because they cannot be changed later. If an attempt is made to assign to a constant, the Qt Script for Applications interpreter will issue an error message and stop.

Constants are public globals if they are declared outside of any enclosing braces. When declared within the scope of some braces, e.g. within an if statment, their scope is local to the enclosing block.

[Prev: Qt Script Language Concepts] [Home] [Next: Classes and Methods]