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
Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.
✨ Frag Lara — deine KI-Lernpartnerin
Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.
Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

