Matchbox 0.2

var

The var keyword declares a variable.

A declaration tells the compiler that a variable exists, including its name and type. The type is required for declarations because it tells Matchbox how much memory to reserve for the variable. A definition is a declaration that also gives the variable an initial value.

Syntax

A variable can be declared without an initial value:

var name int

Assign a value before reading it:

name = 10

A definition initializes the variable immediately:

var name int = 10

An initializer gives the variable its first value. A variable declared without an initializer cannot be read until a later assignment stores a value.

The int annotation can be omitted in a definition because Matchbox can infer the type from the initial value:

var name = 10

See Variables for initialization, scope, and naming rules.