Truncate a String, 1 line solution

Truncate a String, 1 line solution
0
function truncateString(str, num) {

  return str.length > num ? str.slice(0, num).concat('...') : str;

}

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

Can be done with a template literal as well:

return str.length > num ? `${str.slice(0, num)}...` : str;

Sure, why not? I think they hadn’t gotten to template literals at that point, but why not?