Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!