sort() function do in JavaScript? The sort() function sorts the elements of an array in ascending order.
By default, it compares the elements as strings.
You can pass a comparison function as an argument to sort the elements in a different way.