Variables
Last updated
Last updated
A variable is a named storage location which holds some value, like a quantity, the name of a person or a list of order lines. The names of variables are freely chosen by you, the developer. The values of variables are supplied by expressions. Learning to write such expressions is the essence of computer programming.
Variables carry information through the execution of applications. Each step in an application has access to the variables created by the steps preceding it, and each step may create or modify variables which flow downstream to its successors.
A script step may also contain local variables, which exist only in the scope of that particular step. In this document, you will learn how to create and update local variables in script steps.
To declare a local variable in a script step, use a let statement.
Variable names can contain alphabetical letters, underscores or numbers, but cannot begin with a number.
All variables have a type, delineating the set of values they can hold. The type of a variable is inferred from its initial value. If the initial value is, for example, a number, then the variable is destined to ever only hold numbers. To see the type of a variable in a script that you are editing in the Flow Designer, you can let the mouse cursor hover over the variable's name.
To update a local variable in a script step, use a set statement. Updating a variable does not change its type. The type of the new value must be compatible with the type of the previous value.
Only local variables, declared in the same script step, can be updated.
Under some circumstances you might need to explicitly specify the type of a variable. For example, if you are creating a variable x with initial value of 1 but will later update it to have the value null, you should declare the variable as a number.