Array.sort() in Firefox can use boolean values for judgment

Once I was debugging, I found that in Firefox Array.sort() can take boolean values in addition to number values. However, in Node.js Array.sort() only supports number values. Although it didn’t cause bugs, I’m curious about the difference. Difference between JS engines Here are some tests: Firefox const arr = [{num:1}, {num:3}, {num:2}] const numSorted = arr.sort((a, b) => a.num - b.num) console.log(numSorted) > Array [Object { num: 1 }, Object { num: 2 }, Object { num: 3 }] const arr = [{num:1}, {num:3}, {num:2}] const boolSorted = arr....

April 3, 2022 · 3 min