The next building block after types are constants and variables.
Constants are immutable by design, which means their values cannot be
reassigned. Put in another way, they can be assigned once, at their
declaration. When defining a constant you need to provide a
type and a
Constants in JsLIGO are enforced:
Unlike the other syntaxes, JsLIGO doesn't allow variable names to be reused in the same block scope:
However, the following does work:
This is not yet enforced in the experimental version of JsLIGO, but will be in the future.
You can evaluate the constant definition above using the following CLI command:
Variables, unlike constants, are mutable.
⚠️ Please be wary that mutation only works within the function scope itself, values outside of the function scope will not be affected. In other words, when a function is called, its arguments are copied, as well as the environment. Any side-effect to that environment is therefore lost when the function returns.
You can run the
add function defined above using the LIGO compiler