liveBook · Manning

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.

How 5 Manning books explain it

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 and reason about initialization and API behavior.
How deep it goes
Explains lookup and initialization behavior through examples, without cataloging zero values for all types.
Examples
Uses a book counter, a greeting phrasebook, a generic cache, and a maze image lookup.
What you can do after
Apply zero-value behavior to check map membership, increment counters, and initialize a cache’s 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.

Read how Go by Example explains zero value →

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 values to initialize members and mark exclusive resources as invalid after transfer.
How deep it goes
Defines the value through initialization and resource-transfer examples, and warns about invalid states without detailing language mechanics.
Examples
Uses a Person age member and Channel socket resources to illustrate initialization and post-transfer invalid values.
What you can do after
Apply a detectable invalid value after resource transfer, while preserving the class invariant.

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.

Read how API Design Patterns explains zero value →

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.

Read how Go in Action, Second Edition explains zero value →

Also covered in

What to know first

Related concepts

Questions about zero value

What is 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.

Which Manning books explain zero value?

Learn Go with Pocket-Sized Projects, Go by Example, 100 C++ Mistakes and How to Avoid Them, API Design Patterns and Go in Action, Second Edition.

What should I know before learning zero value?

Manning books that teach zero value usually introduce reference, boolean, number type and struct first.

What is zero value a kind of?

Zero value is a kind of value. A value is a quantity, datum, or measure of significance attributed to or represented by an entity, property, expression, or outcome.

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.