DEV Community

Discussion on: Capitalize first letter in every sentence?

Collapse
 
anwar_nairi profile image
Anwar • Edited

If you check the prototype of substr (see the MDN documentation), you can see that there is this second optional parameter length:

String.prototype.substr = function(start: number, length: number = undefined): string

And the documentation states that

If length is omitted, substr() extracts characters to the end of the string.

So when you call word.substr(1), this is the equivalent of:

word.substr(1, word.length);