Truncate a String 0

Tell us what’s happening:
How does this code work?

Your code so far

function truncateString(str, num) {
  if (str.length > num) {
    return (str.substr(0, num) + "...");
  return (str.substr(0, num));

truncateString("A-tistek a-tasket A green and yellow basket", 8);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

Take a look at the documentation of String.prototype.substr