Although you can manually sort the elements in an array when you create it, often you’ll find it useful to sort the array alphabetically or numerically later. Although JavaScript provides the simple sort() method, its simplicity is deceptive. This method will only look at the ASCII value of the first character in a string. This means it’s case-sensitive and uppercase letters will appear before lowercase.
To complicate matters further, the sort() method treats numeric values as strings as well, so that 20 would appear well before 7, because the method sees 20 as a string starting with 2.