Javascript Boolean.compare()

Javascript doesn’t have a builtin that’s comparable to Java’s Boolean.compare(). In fact, the Boolean class has nearly nothing in it, save the constructor, toString() and valueOf().

The functionality can be replicated using the Number constructor.

function booleanCompare(a: boolean, b: boolean) {
    return Number(a) - Number(b);
}