To create an empty slice in Golang, you can use the “empty pair of square brackets” or “make()” function.
Method 1: Using a literal syntax with empty brackets
Use the := operator and an empty pair of square brackets [] followed by the data type of the elements the slice will hold.
Example
package main
import (
"fmt"
)
func main() {
emptySlice := []string{}
fmt.Println(emptySlice)
}
Output
[]
In this example, an empty slice of type string is created using the literal syntax with empty brackets. The slice will have a length of 0 and can be used to store elements of the specified type.
Method 2: Using the built-in make() function
You can also use the “make()” function to initialize an empty slice.
Example
package main
import (
"fmt"
)
func main() {
emptySlice := make([]string, 0)
fmt.Println(emptySlice)
}
Output
[]
In this example, an empty slice of type string is created using the make function with a length of 0.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.
var emptySlice []string