What is Go?

Course 1 · Ch 1
What Go Is, Compiling and Running, and Your First Program
A compiled, statically-typed language built at Google for simplicity and speed — starting with the smallest program that runs

Go (often called Golang to make it searchable) is a compiled language — source code is translated into a standalone executable before it runs, rather than being interpreted line-by-line in a browser console. This is the single biggest difference to keep in mind throughout this course: there's no browser, no console.log-and-refresh workflow — Go code is built, then run, as a real program.

Installing Go and Checking It Works

# In a terminal, after installing Go: go version # go version go1.22.0 windows/amd64

If that prints a version number, Go is installed and ready to use from the command line.

The Smallest Go Program

package main import "fmt" func main() { fmt.Println("Hello, Go!") }

Every runnable Go file has exactly these three pieces. package main marks this file as a program (not a reusable library); import "fmt" pulls in the standard formatting/printing package; func main() is the entry point — execution always starts here, the direct equivalent of the top-level code that ran automatically in every JavaScript example.

fmt.Println is Go's console.log
fmt.Println(...) prints a line of output to the terminal. It's the most-used function in this entire course, exactly as console.log was throughout the JavaScript course.

Running a Go File

# Save the code above as hello.go, then: go run hello.go # Hello, Go!

go run compiles the file into a temporary executable and runs it immediately in one step — the fastest way to try something out. There's also a separate, two-step workflow for producing a permanent program:

go build hello.go # produces hello.exe (Windows) or hello (Mac/Linux) ./hello # runs the compiled program directly, no Go installation needed to run it

go build is what actually happens when shipping a real program — the resulting file runs on its own, with the Go toolchain itself no longer required on the machine that runs it.

Go is strict about unused things
Go refuses to compile if a variable is declared but never used, or a package is imported but never referenced. This feels harsh coming from JavaScript, where unused variables are silently ignored — but it's deliberate, catching real mistakes (like a typo'd variable name) immediately instead of letting them hide.

Comments

// A single-line comment /* A multi-line comment, identical syntax to JavaScript/CSS */

Comment syntax is identical to JavaScript's — // for a single line, /* */ for a block.

Printing Multiple Things

fmt.Println("The answer is", 42) // The answer is 42 fmt.Printf("The answer is %d\n", 42) // The answer is 42 — formatted, like a template literal

Println auto-spaces and joins multiple arguments, then adds a newline. Printf uses placeholder verbs (%d for a number, %s for a string, %v for "any value") inside a format string — closer in spirit to a JavaScript template literal, but with explicit type placeholders instead of ${ }.

ConceptJavaScriptGo
Run codeBrowser / Node, instantlygo run file.go (compiles first)
Print outputconsole.log(...)fmt.Println(...)
Entry pointTop-level script codefunc main() { }
Unused variablesAllowed, silently ignoredCompile error

Coding Challenges

Challenge 1

Write a complete Go program (package main, import "fmt", func main) that prints your name and a short greeting on two separate lines using two calls to fmt.Println.

📄 View solution
Challenge 2

Write a program that uses fmt.Printf with %d to print "Year: 2026" and %s to print "Language: Go" — two separate Printf calls, each using a placeholder rather than concatenation.

📄 View solution
Challenge 3

Write a program that declares a variable message with the value "Compiled and ready", but deliberately never uses it (no Println call referencing it). Try go run on it, note the exact compiler error, then fix it by actually printing the variable.

📄 View solution

Chapter 1 Quick Reference

  • package main — marks a file as a runnable program
  • import "fmt" — brings in the formatting/printing package
  • func main() { } — the entry point; execution always starts here
  • go run file.go — compile and run immediately, for quick testing
  • go build file.go — produce a standalone executable to ship
  • fmt.Println(...) — print a line, auto-spaced and newline-terminated
  • fmt.Printf("...%d...\n", x) — formatted printing with explicit placeholders
  • Unused variables/imports are compile errors, not warnings — Go enforces this strictly
  • Next chapter: variables, Go's basic types, and := vs var