Basic Syntax
Learn the core rules of Go: semicolon insertion, export visibility (Capitalization), and commenting.
βCapital letters in Go are like VIP badges. If a function or variable starts with a Capital letter, it can leave the room (public). If it starts with lowercase, it stays private in the room.β
[Inside package mathutil] βββ CalculateTotal() ββ> Starts with Capital 'C' ββ> π’ PUBLIC (Exported) βββ helperFunction() ββ> Starts with Lowercase 'h' ββ> π PRIVATE (Unexported)
Key Concepts & Rules To Remember
- Visibility is determined purely by capitalization: `ExportedName` vs `unexportedName`.
- No trailing semicolons required β the Go lexer inserts them automatically.
- Go uses `//` for single-line comments and `/* */` for multi-line block comments.
- Naming convention: use MixedCaps/camelCase (e.g., `userID`, `parseJSON`), never snake_case.
1. Exported vs Unexported (Public vs Private)
In Go, there are no `public` or `private` keywords. The first letter of any identifier decides its visibility to other packages.
package wallet
// Exported (Public): starts with Capital 'B'
// Other packages can do wallet.Balance
var Balance = 1000
// Unexported (Private): starts with lowercase 's'
// Only functions inside package wallet can access this
var secretPin = 12342. Naming Conventions
Go developers follow strict naming rules: keep names concise, use CamelCase, and acronyms should be capitalized together (e.g. `httpServer`, `urlID`, `jsonParser`).
// β
Good idiomatic Go:
var maxRetryCount = 5
var apiURL = "https://api.example.com"
// β Unidiomatic (Avoid snake_case):
var max_retry_count = 5Common Beginner Pitfalls & Mistakes
Knowledge Check
Verify your understanding with these interactive practice questions.
Quizzes
Quick checks for understanding
Multiple-choice with inline explanationsβexpand to see why.
Finished this lesson?
Mark it as complete to track your overall Go mastery.