How to initialize an empty map in Golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I’m going to show you how I do initialize an empty map in Golang, to create an empty map I follow a basic style just I will not put any data in it.

Let’s start today’s tutorial How to initialize an empty map in Golang?

Here I will create a sample variable and store an empty map, then I will use the print method to check if it’s empty or not.

Okey, let’s start the code.

package main
 
import "fmt"
 
func main() {
    x := map[string]string{}
    fmt.Println(x)
}

when you run above program it will print map[] like in golang console.

let’s check the output.

get, initialize an empty map, golang

Try it yourself

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts