Skip to content

Glossary: JavaScript Basics

Compare function

Also written: comparison function

A callback given to `sort` that takes two elements, `a` and `b`, and returns a negative number, positive number or 0 to say which comes first, such as `(a, b) => a - b`.

Where the book teaches it

Related terms

sort / toSortedlocaleCompare