Sobes.tech
Junior

¿Qué valores se consideran falsos (falsy) en JavaScript?

sobes.tech AI

Respuesta de la IA

En JavaScript, los valores falsos (falsy) son aquellos que, al convertirse a tipo booleano, se vuelven false. Incluyen:

  • false
  • 0 (cero numérico)
  • -0 (cero negativo)
  • 0n (BigInt cero)
  • "" (cadena vacía)
  • null
  • undefined
  • NaN

Todos los demás valores se consideran verdaderos (truthy).

Ejemplo:

if (!0) {
  console.log('0 — valor falsy');
}
if ("hello") {
  console.log('"hello" — valor truthy');
}