Numerical Sort in JavaScript

By default, Array.prototype.sort() operates on the basis of string comparison.

Numerical Sort in JavaScript

By default, Array.prototype.sort() sorts elements using the UTF-16 code unit sequence. So, pass an appropriate comparison function to the sort function to sort in the numerical order.

Reference

Array.prototype.sort() - JavaScript | MDN
The sort() method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.