Defining a variable
Variables in LIGO can be defined in two ways - by using either the
const can be used both at global (top-level) and local scope (within functions/blocks), while
var can be used for mutable values in the local scope.
Imutable variables using
⚠️ Currently const values are mutable as well, however this is something that will change in the upcoming release. For the time being think of
constas a semantical way to indicate developer intentions.
const four: int = 4;
Mutable variables using
varcan't be used in the global scope
// won't work, use const for global values instead
var four: int = 4;
// value of `number` can be mutated within local scope
function addFour(var number: int): int is
number := number + 4;
} with number;