Why does my code not work with the curly braces?

Hi, Can someone tell me why this code works when I omit the curly braces?

const sortSpeciesByTeeth = (objArr) => {
  objArr.sort((a, b) => a.numTeeth > b.numTeeth)
}

Because the return keyword that you need when you expect to receive a return value from a function is implied when you omit the curly braces.

These are equivalents:

const sortSpeciesByTeeth = (objArr) => {
  return objArr.sort((a, b) => a.numTeeth > b.numTeeth)
}
const sortSpeciesByTeeth = objArr => objArr.sort((a, b) => a.numTeeth > b.numTeeth)

5 Likes

Ahhh that makes sense…Thank you!!!