Can constants be computed at runtime in Go, and what are the limitations of const compared to var?

Last updated 20 June 2026

  • No: constants must be computable at compile time from literals and constant expressions, so const t = time.Now() won't compile.

  • Constants are limited to booleans, numbers, strings, and runes. Slices, maps, structs, and pointers need var.

  • Untyped constants have high precision and adapt to context (e.g. usable as int or float64 without conversion). Use var for runtime-computed or changing values.

  • https://www.reddit.com/r/rust/comments/1h15md8/goodbye_rust_i_wish_you_success_but_im_back_to_c/
  • https://www.reddit.com/r/golang/comments/1gfjnzm/since_when_is_senior_golang_developer_expected_to/
All Golang interview questions