How to check data type in Golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today’s Tutorial will focus on to check datatype in golang in the easiest way, here we try to check datatype in just two lines of code.

Follow the below tutorial if you are struggling in installing GO in windows.

Let’s start today’s tutorial How to check the data type of variable in Golang?

Here, we will use the go reflect package to check data type and to show in the console we will use fmt.Print() method.

let’s dive into code…

package main

import (

func main() {
	data := 123
	dataType := reflect.TypeOf(data).Kind()

in the above code, we are hole 123 in data variable and pass in reflect.TypeOf and it returns their datatype.

it will show output int

Try it yourself

All the best 👍

Premium Content

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


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.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Stay tuned working on React Js Cheat Sheets Book

Related Posts