Truncate string - understanding why this works

Pretty sure I’m doing it wrong but it passes all the tests :sweat_smile:

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (str.length > num) {
    return str.slice(0, num) + '...'
  }
  return str;
}