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

146
Vistas
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 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