Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda