How to Use the make Function for Slices and Maps in Go

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)