Zero value of a slice is nil
.
A nil
slice has length and capacity of 0.
A nil
slice has no underlying array.
A non-nil slice can also have length and capacity of 0, like []int{}
or make([]int, 5)[5:]
.
Any type that has nil
values can be converted to nil
slice:
https://codeeval.dev/gist/d36abe37a7da46e28a2374a549a1f6cd
To test whether a slice is empty, check if len(s)
is 0: