Skip to content

Variables

Beginner · Fundamentals

Variables in go are used to bind a value to a name, just like in other programming languages.

There are two ways to define variables in go.

Give the variable a name so it can be declared.

Show hint
Variables must have names.

Source

Declare a variable before assigning to it.

Show hint
It is missing a symbol used to declare and initialize variables.

Source

A variable declaration needs a type or an initial value.

Show hint
Could it be missing the variable type?

Source

See what happens when a block reuses a name with a new type.

Show hint
Variables can be redeclared in new blocks, but it is missing something. What is it?

Source

Constants must be given a value when declared.

Show hint
Constants need initialization.

Source

Constants cannot be reassigned after declaration.

Show hint
Constants can't be changed.

Source