Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

variables-types-go

Variables and types

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Variables and types: the syntax, patterns, and safety habits you need before advancing in Go.

Teams still ship Variables and types in Go codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Variables and types in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Go is statically typed like Java and C#, not dynamically typed like Python. Variables declare with var or short declaration := inside functions.

Basic types

  • int, int64, float64 — numeric types
  • string — UTF-8 text, immutable
  • booltrue or false
  • byte (alias for uint8), rune (alias for int32) — bytes and Unicode code points

Declaration styles

var count int = 10
name := "Ada"          // short declaration, type inferred
var ratio float64 = 0.75

:= works inside functions only. Package-level variables need var with explicit types when inference is unavailable.

Important interview questions and answers

  1. Q: var vs :=?
    A: var works at package or function scope; := is short declaration inside functions with type inference.
  2. Q: Zero values?
    A: Uninitialized variables get zero values: 0 for numbers, "" for strings, false for bool, nil for pointers/slices/maps/channels.

Self-check

  1. What is the zero value of an int?
  2. Can := be used at package level?

Pitfall: := only works inside functions—package-level variables need var, unlike short declarations at module scope in some languages.

Interview prep

var vs :=?

var works at package or function scope; := is short declaration inside functions with type inference.

Zero values?

0 for numbers, "" for strings, false for bool, nil for pointers/slices/maps/channels/interfaces.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • := when?
  • zero value idea?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump