The difference between substr vs. substring in JavaScript bites me more often than any other API confusion in the language. The only difference is in the second parameter. Do you know what each of these will return?

substr vs. substring

String.prototype.substr() and String.prototype.substring() have identical looking APIs in that they both take two parameters and the first parameter for both methods is the numerical index of the string we’re going to be doing substitutions on. The second parameter is where they differ.

Substring’s second parameter is the numerical index on which you stop the substitution; substr’s second parameter is the length of the substitution.

So, to review the code from above:

I hope that helps!