The JavaScript Array function, .sort()by default, converts array elements to strings before performing comparisons.
You can override this:
x.sort(function(e1, e2) { return e1 - e2; });
(A missed function should return a number that is negative, zero or positive, depending on whether the first element is less than, equal to, or greater than the second.)
I have never seen the rationale for this odd aspect of language.