juniorGolang
What is the blank identifier `_`?
Updated Apr 28, 2026
Short answer
The blank identifier is a special identifier used to discard values returned by a function or a range loop.
Deep explanation
Because Go throws a compile-time error if a declared variable is not used, _ provides a way to explicitly ignore unwanted return values. It can also be used in imports to execute a package's init() function without using its exported API.
Real-world example
Importing database drivers like _ "github.com/lib/pq" to register the driver in the database/sql package without calling it directly.
Common mistakes
- Ignoring errors with `_`, which masks failures and makes debugging extremely difficult.
Follow-up questions
- Can you read from the blank identifier?