Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Show type of variable - reflect.TypeOf

  • reflect
  • TypeOf

You can also use the TypeOf function of the reflect package.

package main

import (
	"fmt"
	"reflect"
)

func main() {
	a := 42
	fmt.Println(reflect.TypeOf(a)) // int

	b := 3.14
	fmt.Println(reflect.TypeOf(b)) // float64

	c := "hello world"
	fmt.Println(reflect.TypeOf(c)) // string

	d := []string{}
	fmt.Println(reflect.TypeOf(d)) // []string
}
int
float64
string
[]string