The solution is a bit of boolean sweetness:
["foo", "", "bar"].sort((a, b) => a && b ? a.localeCompare(b) : !a - !b ); // [ "bar", "foo", "" ]
For instance, if a is empty but b is not, the else case in the ternary resolves to
true - false ⇒
1 - 0 ⇒
1 which means: put b before a.