Variables and constants
LIGO features mutable variables, that is, variables whose values can be reassigned. By contrast, constants can be assigned only once.
Variables
To declare a variable, use the keyword let
instead of the keyword const
, which is for constants.
To assign new values to the variable, use the =
operator, as in this example:
Silent variables
The compiler warns you when you declare a variable but do not use it. To ignore a variable, turn it into a silent variable by prefixing its name with an underscore or using an underscore as its name.
For example, LIGO entrypoints receive a parameter and the current value of storage as arguments. If the entrypoint code doesn't access one or both of these arguments, prefix the argument name with an underscore to hide the compiler warning, as in this example:
Constants
Constant values cannot be reassigned after they are declared.
To declare a constant, use the keyword const
, as in this example:
You cannot assign a new value to a constant in the same scope:
However, the following example works because the constants are in different scopes: