val (immutable) or var (mutable).
Outside functions, use const or (rarely) global.
Keywords val and var
val declares a variable that is assigned exactly once (immutable):
var declares a variable that may be reassigned:
{ ... } opens a nested scope:
Parameters of a function
Function parameters work exactly like local variables. They can be reassigned, but changes do not affect the caller’s state:userId visible inside demo, the parameter must be declared as mutate userId.
See mutability.
Constants
Global-scope constants are declared withconst outside functions:
stringCrc32("...") and similar.
See strings.
To group integer constants, also use enums.
Global variables
Tolk has theglobal keyword to declare variables outside functions:
get fun, onInternalMessage, and more low-level).
So, a particular global must be initialized at some place where its forward usage is expected.