How JavaScript array sorting works, why compare functions matter, and how to avoid string-order surprises and mutation bugs.