liveBook · Manning

Type coercion

Type coercion is the conversion of a value from one type to another to make it compatible with an operation or expression.

How 2 Manning books explain it

Systems Programming with Zig

Type coercion is the conversion of a value from one type to another so that an operation can accept it.

How it is used
Makes conversions unambiguous so programmers choose types deliberately and avoid unexpected changes to data.
How deep it goes
Defines coercion restrictions and explains pointer constness, while deferring the built-in functions typically used for explicit conversions.
Examples
Contrasts boolean-to-integer and integer-to-float conversions with assigning a mutable pointer to a constant-pointer variable.
What you can do after
Evaluate whether a conversion needs to be explicit and recognize when a mutable pointer can serve as a constant pointer.

Read how Systems Programming with Zig explains type coercion →

Secrets of the JavaScript Ninja, Third Edition

The implicit conversion of a value from one type to another during an operation or expression evaluation.

How it is used
Clarifies JavaScript’s implicit conversions as a source of surprising results and motivates type checking as a way to catch some errors.
How deep it goes
Defines implicit conversion and demonstrates string and array-object outcomes, but does not enumerate coercion rules.
Examples
Shows `1 + "2"`, `[] + {}`, and `[] + ""` to demonstrate unexpected conversion results.
What you can do after
Understand when JavaScript converts operands implicitly and how TypeScript can flag incompatible predicted results.

Read how Secrets of the JavaScript Ninja, Third Edition explains type coercion →

Related concepts

Questions about type coercion

What is type coercion?

Type coercion is the conversion of a value from one type to another to make it compatible with an operation or expression.

Which Manning books explain type coercion?

Systems Programming with Zig and Secrets of the JavaScript Ninja, Third Edition.

What is the difference between type coercion and strong typing?

Type coercion is the conversion of a value from one type to another to make it compatible with an operation or expression. Strong typing is a type-system discipline that enforces type consistency and limits invalid operations or implicit conversions between incompatible types.

What is type coercion a kind of?

Type coercion is a kind of data conversion. Data conversion is the transformation of a value or data from one type, format, or representation to another, explicitly or implicitly.

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.