How to Create an Empty Slice in Golang

0 min read 60 words

If you would like to create an empty slice in Go, then you can do the following:

Option 1 – Initialize an Empty Slice in Go

package main

import "fmt"

func main() {
    b := []string{}
    fmt.Println(b == nil)
}

Option 2 – Using make()

package main

import "fmt"

func main() {
    c := make([]string, 0)
    fmt.Println(c == nil)
}
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags