Zero value
A zero value is the default, type-dependent value assigned when a variable, field, or newly allocated value has no explicit initial value.
Learn Go with Pocket-Sized Projects
A zero value is the default value assigned to a Go variable or returned for an absent or uninitialized value of its type.
- How it is used
- Uses zero values to handle missing map entries, count books, and reason about cache initialization.
- How deep it goes
- Explains zero values through map lookups and an uninitialized cache map, without developing rules for every Go type.
- Examples
- Shows an unsupported-language greeting, a book counter, cache methods, and an out-of-bounds image lookup.
- What you can do after
- Diagnose/debug with it when a missing key yields an empty value or a cache contains an uninitialized map.
Read how Learn Go with Pocket-Sized Projects explains zero value →
Go by Example
A zero value is the default value assigned to a Go variable when no explicit initializer is provided.
- How it is used
- Simplifies test environments and service types by removing unnecessary initialization before use.
- How deep it goes
- Explains practical zero-value design through builders, pointer nil panics, lazy map initialization, option ambiguity, and copying cautions.
- Examples
- Demonstrates testEnv with strings.Builder fields, nil pointer builders, and a Shortener that initializes its map on demand.
- What you can do after
- Apply zero-value-friendly type designs while handling nil maps, pointer initialization, ambiguous option defaults, and stateful-value copying.
100 C++ Mistakes and How to Avoid Them
A zero value is the type-dependent zero-initialized value assigned to an object or variable by a relevant initialization operation.
- How it is used
- Uses type-dependent zero values to initialize objects and mark moved-from exclusive resources as lacking ownership.
- How deep it goes
- Explains initialization forms, undefined behavior, class invariants, and sentinel selection, but does not formalize language-standard rules.
- Examples
- Demonstrates Person initialization, explicit member constructors, invalid ages, and resetting pointers or value resources after transfer.
- What you can do after
- Diagnose uninitialized members and choose zero or invalid values that preserve class invariants during resource transfer.
Read how 100 C++ Mistakes and How to Avoid Them explains zero value →
API Design Patterns
A zero value is the empty or numerically zero representation that a data format or type uses when no distinct null representation is available.
- How it is used
- Guides API field and default design when formats cannot represent null or missing primitive values.
- How deep it goes
- Explains Boolean, numeric, and map consequences, but defers numeric default handling to serialization design.
- Examples
- Uses ChatRoom permissions, allowChatbots, disallowChatbots, numeric zero, and empty-versus-null maps.
- What you can do after
- Evaluate API defaults for ambiguity, intentional zero values, predictable behavior, and future default changes.
Go in Action, Second Edition
A zero value is the default value assigned to a newly declared Go variable when no explicit initial value is provided.
- How it is used
- Uses default values to make declarations and map access immediately usable without mandatory initialization.
- How deep it goes
- Explains defaults and map behavior with runnable patterns, but defers other zero-value details to later treatment.
- Examples
- Demonstrates default integers, missing map entries, Boolean membership maps, and numeric word-count lookups.
- What you can do after
- Apply zero values in declarations and map lookups, and diagnose absent keys with two-value assignment.
Related concepts
- Mapproduced by · A map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- named result parameterused by · A named result parameter is a Go function result parameter declared with an identifier that can be referenced within the function body and is initialized to its type's zero value.
- missing valuecontrasts with · A missing value is a marker or condition indicating that an expected data value or reference is absent, unavailable, unknown, or inapplicable.
- attributeconfigures · An attribute is a named property, value, or piece of information associated with an entity, object, or program element.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




