Compares this object to another object of the same type.
The object to compare with.
A negative number if this object is less than the other, zero if they are equal, or a positive number if this object is greater than the other.
(1).compareTo(2);
"a".compareTo("b");
true.compareTo(false);
const string1 = "apple";
const string2 = "banana";
const stringComparison = string1.compareTo(string2);
console.log(stringComparison); // Output: -1 (Example output; actual output will vary)
const number1 = 10;
const number2 = 5;
const numberComparison = number1.compareTo(number2);
console.log(numberComparison); // Output: 1 (Example output; actual output will vary)
const date1 = new Date("2023-01-01");
const date2 = new Date("2023-01-15");
const dateComparison = date1.compareTo(date2);
console.log(dateComparison); // Output: -1 (Example output; actual output will vary)
Generated using TypeDoc
Interface representing a comparable object that can be compared to another object of the same type.
Comparable
Since
version 1.4.0
Author
Manuel Santos ney.br.santos@gmail.com