As I was attempting to organize an Array, I observed a discrepancy between the behavior in Chrome V79 and Firefox Dev Edition V72 (both desktop versions).
Here is the test:
console.log([4, 2, 5, 1, 3].sort((a, b) => a>b));
console.log(Array.prototype.sort.call([4, 2, 5, 1, 3], (a, b) => a>b));
In Firefox Dev, I see this result:
https://i.sstatic.net/M3Ucx.jpg
However, in Chrome, I am presented with this result:
https://i.sstatic.net/bsMVp.jpg
When I pass the same array with var, a different result appears:
https://i.sstatic.net/tfZfs.jpg
The Array gets sorted and the variable gets rewritten, but the returned version of the Array remains unsorted. This leads to no sorting when passing the Array directly without any var.
According to MDN's reference page, shouldn't it return the sorted Array?
Why is there a difference?
Note: In the Example Images, both examples involve me practicing the
call
function and were mistakenly left in. Please disregard them as they are identical.