In javascript, both method do the same job, except original array mutation.
sort()
method mutate the original array. No need to store the return value in variable.
var arr = [1,2,1000];
arr.sort();
console.log(arr);
// console.log() => 1, 1000, 2
toSorted()
method does not mutate the original array. Need to store the return value in variable.
var arr = [1,2,1000];
var sortedArr = arr.toSorted();
console.log(sortedArr);
// console.log() => 1, 1000, 2
One thing to add about the both function:
sort() is way more perf than toSorted()