Type Conversion in JavaScript
JavaScript is loosely typed, meaning variables can hold any type and types can change. Type conversion (or coercion) is the process of converting a value from one type to another.
There are two kinds: implicit (automatic by JS) and explicit (manual by the developer).
Implicit Conversion (Coercion)
JavaScript automatically converts types in certain operations, especially with the + operator or loose equality (==).
Loose vs Strict Equality
== allows coercion, === requires same type and value.
Explicit Conversion
Use built-in functions to convert types manually.
- String() or .toString() – to string
- Number() or parseInt/parseFloat – to number
- Boolean() – to boolean
Truthy and Falsy Values
In conditions, values are coerced to boolean. Falsy values become false:
- false, 0, "", null, undefined, NaN
Everything else is truthy.
Common Pitfalls
Unexpected coercion can cause bugs. Prefer explicit conversion and strict equality (===).
Quick Quiz
We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.


