Variables
Variable Declaration
1. Using var keyword
var keywordvar name string // declares variable with zero value ("")
var age int = 25 // declares and initializes
var isActive = true // type inferred from value2. Short Declaration (:=)
:=)name := "John" // type string inferred
age := 25 // type int inferred3. Multiple Declarations
var (
name string
age int
isValid bool
)
// Multiple short declarations
name, age := "John", 25Variable Scope
1. Package Level
2. Function Level
3. Block Level
Zero Values
Constants
Variable Naming Conventions
Best Practices
Common Patterns
1. Error Checking
2. Multiple Return Values
3. Blank Identifier
Variable Type Conversion
Tips and Tricks
Additional Resources
Last updated