What is Go?
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
If that prints a version number, Go is installed and ready to use from the command line.
The Smallest Go Program
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(...) 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
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 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.
Comments
Comment syntax is identical to JavaScript's — // for a single line, /* */ for a block.
Printing Multiple Things
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 ${ }.
| Concept | JavaScript | Go |
|---|---|---|
| Run code | Browser / Node, instantly | go run file.go (compiles first) |
| Print output | console.log(...) | fmt.Println(...) |
| Entry point | Top-level script code | func main() { } |
| Unused variables | Allowed, silently ignored | Compile error |
Coding Challenges
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 solutionWrite 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 solutionWrite 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 solutionChapter 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