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

148
Visualizações
Javascript: Array Sort returns different result for Chrome and Firefox

Consider following data for testing the scenario.

When I use sort method on array with comparison function:

['a', 7, 65, '65'].sort((a,b) => a-b)

Output for Mozilla:

[ 7, 65, "65", "a" ]

Output for Chrome

["a", 7, 65, "65"]

The output seems to be different in both. Please focus on the reason why this happens rather than giving the solution on how to sort.

The objective of this question is to understand why is there a different implementation of sorting when it compares NaN in different engines.

Example: 'a' - 65 will return Nan;


[Update] Sorting ['a', 65].sort((a,b) => a-b)

Chrome: [65, 'a']

Mozilla: ['a', 65]


Sorting [65, 'a'].sort((a,b) => a-b)

Chrome: ['a', 65]

Mozilla: [65, 'a']

Why does this behavior happen

about 4 years ago · Juan Pablo Isaza
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