return typeof a < typeof b ? -1 : 1;
I made my own tests and I think this is the "ordering" of the different types:
function < number < object or array < string < undefined
Is this how JS actually does the comparison?
typeof operator returns a string. String are compared by its numeric value.
< comparison order would be:
type charCode ("tfnosux".charCodeAt(i)) Example boolean 98 true function 102 Date number 110 123 object 111  string 115 "" undefined 117 undefined xml 120 <x></x>
tfnosux are the first characters of the types. The
xml, is less commonly known, and can be obtained by using
typeof on EX4.
It is not importance.
typeof returns a string, and the comparison operators work for strings, by performing a "a simple lexicographic ordering on sequences of code point value values".
Basically, if one string starts with the other, then that is the greater of the two, otherwise the first character position that differs between the two is compared.
See section 11.8.5 of the spec