The sort method's callback function in javascript needs to return a value, when you put {}
around the function content you are essentially returning undefined
from the function and your code inside the function is just an expression being executed inside it
When you use {}
you need an explicit return statement to return the value
console.log([10, -2, 49].sort((a,b) => a-b))
console.log([10, -2, 49].sort((a,b) => {return a-b;}));
In the first case it works because when you write the function with that syntax, it has an implicit return.
You can know more about explicit and implicit return in this post:
Arrow functions and the use of parentheses () or {} or ({})