Quick actions

cmd+k|ctrl+k

Navigation

Languages

Slices / Zero value of slice / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-04-18T17:13:27Z

Updated

2019-04-18T17:13:27Z

package main

import "fmt"

func main() {
	s := []int(nil)
	if len(s) == 0 {
		fmt.Printf("s  is empty: %#v\n", s)
	}

	var s2 []int
	if len(s2) == 0 {
		fmt.Printf("s2 is empty: %#v\n", s2)
	}

	s3 := make([]int, 0)
	if len(s2) == 0 {
		fmt.Printf("s3 is empty: %#v\n", s3)
	}

}
INFO