Static Typing and Strings
Go is statically typed, meaning variable types are checked and known at compile time. This catches bugs before your code ever runs.
Static vs Dynamic
- Static (Go): Types are fixed. Your editor can highlight errors immediately.
- Dynamic (Python/JS): Types are determined at runtime, which can lead to unexpected “hidden” bugs.
Concatenating Strings
You can join two strings together using the + operator.
firstName := "Eddie"
lastName := "Cabot"
fullName := firstName + " " + lastName // "Eddie Cabot"
Strict Type Rules
You cannot concatenate a string with other types like int or float64 directly. You must convert them first.
var age int = 25
// This will FAIL:
// message := "Age: " + age