Type Conversion in JavaScript

Tipos de DatosOperadores

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

Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.

✨ Pregunta a Lara — tu compañera de estudio con IA

Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.


Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.

Sigue Tu Progreso 🚀

Aprende más fácilmente siguiendo tu progreso completamente gratis.