W3Schools is Powered by W3. The callback function or, technically, comparison function receives two arguments called a and b by convention and should return 1 if the first argument should preceed the second, -1 if the second argument should preceed the first and 0 if they are equal. LOG IN. The boolean values are coerced to integer 0 and 1 to calculate the difference. You can use string1. The aim of this post is to explain to you why, why not and how the sort method works when sorting an array of numbers. This method returns a number indicating whether a string comes before, after, or is the same as a given string in the sort order.