Empty Slice literal in golang

package main

import (

func main() {

	var x = []int{}
	var y []int
	fmt.Println(x == nil) // why it is not nil
	fmt.Println(y == nil)

X is not nil beacuse you are initializing it to a en empty slice.
In the secornd case, y is nil because it is only declared and Go initializes it to nil.
A slice is a structure to a array, with capacity y length its default zero value isnil . The nil slice has a length and capacity of 0 and has no underlying array. When we create a slice with the make function, all elements are initialized to 0.

1 Like