When you write 5
directly in the source-code that's called a constant. Same goes for writing true
. The only difference is that the former is an untyped constant and the latter a typed constant.
The difference lies in that there's no ambiguity about what type true
should have – it'll always be bool
but in the case of 5
that's not so obvious and depends on the context.
The Go compiler will figure out what type to give the constant on compilation. The details of this are described in Go's language specification.
Edit:
I realized that there's a mistake in my answer: true
is in fact also untyped according to the spec because it may be utilized anywhere where a type deriving from bool
is expected. That means:
type MyBool bool
func DoNothing(b MyBool) {}
DoNothing(true) // true is coerced to MyBool
The answer is still valid, though. The distinction between typed and untyped constants holds.