×

go · level 1 · unit 3 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Every value has a .

Every value in Go has a type, which says what kind of thing it is. A string is text. An is a whole number, like 7. A has a decimal point, like 2.5. A is true or false.

Quotes change everything. "5" + "3" joins two strings into "53", but 5 + 3 adds two numbers to make 8. Mix a string and a number with +, and Go refuses to run.

A box keeps its type for life. age := 12 makes an int box, so later it can hold 13 but never "thirteen". You can also name the type yourself: var age int = 12.

package main
import "fmt"
func main() {
	var name string = "Rex"
	var age int = 3
	var weight float64 = 12.5
	var isGoodBoy bool = true
	fmt.Println(name, age, weight, isGoodBoy)
}

Scan fills a box in its own type, so age := 0 and then fmt.Scan(&age) reads a number.