juniorGolang

What are exported and unexported identifiers?

Updated Apr 28, 2026

Short answer

Exported identifiers start with an uppercase letter and are visible outside their package. Unexported start with a lowercase letter.

Deep explanation

Go uses capitalization instead of keywords like public or private. If a variable, function, struct, or struct field starts with an uppercase letter (e.g., User), it is exported. If lowercase (e.g., password), it is unexported and visible only within the declaring package.

Real-world example

Hiding internal implementation details (like a database connection pool state) while exporting the methods needed to execute queries.

Common mistakes

  • JSON marshaling a struct with lowercase fields. The `encoding/json` package cannot see unexported fields, so they will be silently ignored.

Follow-up questions

  • Can unexported fields be accessed by methods of the same struct in a different file?

More Golang interview questions

View all →