Back to Concepts Roadmap
๐ŸŸก Level 1 โ€” Fundamentals
Foundation

Basic Types

Explore Go numeric primitives, booleans, immutable strings, bytes, and Unicode runes.

Real-World Analogy (Mental Model)

โ€œTypes are like specific container shapes: a water cup, a shoebox, and a letter envelope. You can not pour soup into an envelope โ€” Go enforces this strictly to prevent runtime crashes.โ€

Architecture & Memory MapVisual Model
[String: "Go ไธ–็•Œ"]
  โ”œโ”€โ”€ Bytes: [71, 111, 32, 228, 184, 150, 231, 149, 140] (9 bytes total)
  โ””โ”€โ”€ Runes: ['G', 'o', ' ', 'ไธ–', '็•Œ'] (5 Unicode characters)

Key Concepts & Rules To Remember

  • Integers: `int`, `int8`, `int16`, `int32`, `int64` and unsigned `uint` variants.
  • Floating points: `float32` and `float64` (default for decimals).
  • Strings: Immutable sequences of UTF-8 bytes.
  • `byte` is an alias for `uint8` (raw 8-bit byte), `rune` is an alias for `int32` (Unicode character code point).
Step-by-Step Code

1. Integers and Floats

In Go, `int` is architecture-dependent (64-bit on 64-bit systems). Type conversion is ALWAYS explicit โ€” Go never silently converts `int` to `float64`.

example.goGo 1.24+
var x int = 42
var y float64 = float64(x) // Explicit conversion required!
Step-by-Step Code

2. Bytes vs Runes

Because Go natively supports UTF-8, English letters take 1 byte, while emojis and international characters take 2โ€“4 bytes. A `rune` represents a single full character.

example.goGo 1.24+
s := "Hi ๐Ÿš€"
fmt.Println(len(s)) // 7 bytes (H:1, i:1, space:1, rocket:4)

// Range iterates by RUNES (characters), not raw bytes:
for index, char := range s {
    fmt.Printf("Char %c at byte index %d\n", char, index)
}

Common Beginner Pitfalls & Mistakes

Mistake: Trying to modify a string character in-place like `s[0] = 'A'`.
โœ… Correct Way: Strings in Go are completely immutable. Convert to a byte slice first: `b := []byte(s); b[0] = 'A'; s = string(b)`.
Self Assessment

Knowledge Check

Verify your understanding with these interactive practice questions.

Quizzes

Quick checks for understanding

Multiple-choice with inline explanationsโ€”expand to see why.

What is a `rune` in Go?

Finished this lesson?

Mark it as complete to track your overall Go mastery.