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.
Exercises
Section titled “Exercises”variables1 compile
Section titled “variables1 compile”Give the variable a name so it can be declared.
Show hint
Variables must have names.variables2 compile
Section titled “variables2 compile”Declare a variable before assigning to it.
Show hint
It is missing a symbol used to declare and initialize variables.variables3 compile
Section titled “variables3 compile”A variable declaration needs a type or an initial value.
Show hint
Could it be missing the variable type?variables4 compile
Section titled “variables4 compile”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?variables5 compile
Section titled “variables5 compile”Constants must be given a value when declared.
Show hint
Constants need initialization.variables6 compile
Section titled “variables6 compile”Constants cannot be reassigned after declaration.
Show hint
Constants can't be changed.