Use the make built-in function to initialize slices with length/capacity and maps with initial capacity in Go.
Use the make built-in function to initialize slices and maps with a specific capacity or length, avoiding nil panics. For slices, make allocates a backing array; for maps, it initializes the hash table.
// Slice: length 3, capacity 5
nums := make([]int, 3, 5)
// Map: initial capacity 10
scores := make(map[string]int, 10)
The make function creates ready-to-use slices and maps by allocating the necessary memory upfront. Unlike regular variables, which start as empty placeholders, make prepares the data structure so you can immediately add items without errors. Think of it as setting up a table with specific seats before guests arrive, rather than trying to add chairs one by one as people show up.