Truncate a String. Why do we need to compare string length and the number?

I checked the documentation for slice function, and it doesn’t say the endpoint need to be smaller than string length. I tried my code in MDN String​.prototype​.slice() documentation, and it works fine. But not in freecodecamp, so I am really confusing why do we need to make sure the the str.length is bigger than the number to do the slice?

Following are the code I tested in MDN.

> var str = 'A-tisket a-tasket A green and yellow basket';
> console.log(str.slice(0, "A-tisket a-tasket A green and yellow basket".length+2));
> //output: "A-tisket a-tasket A green and yellow basket"

Is this your whole code for the challenge?

In the challenge you have a string and a max length, and if the string is longer than the max length you need to truncate the string and add dots at the end - if the string doesn’t exceed that length than the dots shouldn’t be allowed.

So it is not the slice method that needs the check, because if the length added in the slice is longer than the string length it returns the whole string - it is adding the dots or not that need the check

aha, I see.
So the problem is my codes allow extra “…” even the number is bigger than the string length.
Got it now, thanks for the pointing out!