concept empty slice in category go

appears as: empty slices, n empty slice, An empty slice
Go in Action

This is an excerpt from Manning's book Go in Action.

You can also create an empty slice by declaring a slice with initialization.

Listing 4.23. Declaring an empty slice
// Use make to create an empty slice of integers. slice := make([]int, 0) // Use a slice literal to create an empty slice of integers. slice := []int{}

An empty slice contains a zero-element underlying array that allocates no storage. Empty slices are useful when you want to represent an empty collection, such as when a database query returns zero results (see figure 4.11).

Figure 4.11. The representation of an empty slice

Regardless of whether you’re using a nil slice or an empty slice, the built-in functions append, len, and cap work the same.