Which types are comparable in Go and can be used as map keys or with the == operator?

Last updated 20 June 2026

  • Comparable (usable with == and as map keys): booleans, numerics, strings, pointers, channels, interfaces, and structs/arrays whose fields/elements are all comparable.

  • Slices, maps, and functions are not comparable: they can only be compared to nil, so map[[]byte]int won't compile.

  • Interface comparison panics at runtime if the dynamic type isn't comparable. In generics, the comparable constraint restricts type parameters to ==-able types.

  • https://www.freecodecamp.org/news/how-to-work-with-collections-in-go-using-the-standard-library-helpers/
  • https://dev.to/arshiargh/go-maps-deep-dive-part-0-understanding-the-basics-3pjc
All Golang interview questions