Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Why does type conversion for [] and !![] return not the same result?

Why does type conversion for [] and !![] return not the same result?

console.log([] == false); // true
console.log(!![] == false); // false

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

For the first output: https://262.ecma-international.org/5.1/#sec-11.9.3

[] == false is evaluated as ToPrimitive([]) == ToNumber(false) which is ToNumber([]) == ToNumber(false) and finally 0 == 0.

The conversion chain step by step:

We're starting with [] == false.

Step 1:

  1. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

Now, we have [] == 0.

Step 2:

  1. If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x) == y.

Some examples of this conversion chain:

console.log(Number([]));
console.log(Number(false));
console.log([0] == false);
console.log(['0'] == false);
console.log([1] == true);
console.log(['1'] == true);
console.log(['0'] == 0);
console.log([1] == '1');
console.log([1,2,3] == '1,2,3');

For the second output: an array (even empty) is truthy. ![] returns false. !false returns true.

Some examples:

console.log(Boolean([]));
console.log(![]);
console.log(!![]);

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda