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
Az anyagokat átnéztük és ellenőriztük, de hibák továbbra is előfordulhatnak. A tartalom kizárólag oktatási célt szolgál, ezért saját felelősségre használd, és szükség esetén ellenőrizd más forrásokkal is.
✨ Kérdezd Larát — a tanulási partnered
Fedezd fel a személyre szabott tanulási támogatást. Lara elmagyarázza az anyagot, összefoglalja a témákat és megválaszolja a kérdéseidet — az Go csomagtól elérhető.
Lara segít gyorsabban tanulni — kizárólag a ReadyTools Go, Plus és Max tagoknak.


