Shuffling an array using sort method and Math.random [duplicate]

I understand the sort method takes a comparator method which has a and b as parameter and depending upon the returned value (1, 0, -1) the array is sorted.

But how does the following code work? It shuffles the items in the array randomly using the sort function.

const a = [1, 8, 3, 5, 2].sort(()=>Math.random() - 0.5);
console.log(a);