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

169
Vistas
Inconsistent behavior of 'greater than or equal' and 'equality' operators regarding 'undefined'

If the equality (strict or not) operator returns true for undefined...

console.log(undefined == undefined)

...why does the greater or equal than operator returns false?

console.log(undefined >= undefined)

The MDN page says that the operands are compared using the Abstract Relational Comparison, but that refers to greater than (or less than) part. Thus, it seems to me that the greater than or equal should provide the same algorithm for equality, isn't that correct?

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

0

Thus, it seems to me that the greater than or equal should provide the same algorithm for equality, isn't that correct?

No, that algorithm is not involved here. The spec defines the evaluation of >= as

  1. Let lref be the result of evaluating RelationalExpression.
  2. Let lval be ? GetValue(lref).
  3. Let rref be the result of evaluating ShiftExpression.
  4. Let rval be ? GetValue(rref).
  5. Let r be ? IsLessThan(lval, rval, true).
  6. If r is true or undefined, return false. Otherwise, return true.

So the only algorithm involved is IsLessThan, which will convert its operands to numbers if they are not already numbers (or strings).

undefined gets converted to NaN and Number::lessThan returns undefined if any operand is NaN, which, according to step 6 above results in false.

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