I am using sort() for quite sometime in JavaScript but today I encountered something which is confusing.
Example 1
Here is a snapshot of my chrome console where I am trying to sort an array.
Step 1. aa is an array decalred with some integer values.
Step 2. Result of aa.sort() is unexpected, as yellow highlights clearly shows that that array is not sorted.
Step 3. Sorting the array using a compare function ** inside the sort. And this works perfectly.
Example 2
Here is another example -
.
Simply using **sort() sorts the array in default ascending order while same is not happening in Example 1.
I want to know exactly what goes inside sort() method.