Difference between substr() and substring() in JavaScript Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In JavaScript Both of the functions are used to get the specified part of the string, But there is a slight difference between them. substr() and substring() are string methods used to extract parts of a string. The main difference is that substr() accepts a length parameter, while substring() accepts start and end indices. JavaScript str.substr() FunctionThe str.substr() function returns the specified number of characters from the specified index from the given string. Syntax:str.substr(start, len);Example: This example uses only one parameter for both functions and produces the same output. JavaScript const str1 = "GeeksForGeeks"; const substrResult = str1.substr(7); const substringResult = str1.substring(7); console.log("Str.substr(7) =", substrResult); console.log("Str.substring(7) =", substringResult); OutputStr.substr(7) = rGeeks Str.substring(7) = rGeeks JavaScript str.substring() FunctionThis function gets the characters from a string, between two specified indices, and returns the new string. Syntax:str.substring(start, end);Example: This example uses the parameter (3, 7) for both functions and returns the output. JavaScript const str1 = "GeeksForGeeks"; const substrResult = str1.substr(3, 7); const substringResult = str1.substring(3, 7); console.log("Str.substr(3, 7) =", substrResult); console.log("Str.substring(3, 7) =", substringResult); OutputStr.substr(3, 7) = ksForGe Str.substring(3, 7) = ksFo Difference between substr() and substring()Featuresubstr()substring()Syntaxstr.substr(start, length)str.substring(start, end)Parametersstart: Starting indexstart: Starting indexLengthlength: Number of characters to extractend: Ending index (exclusive)Negative IndexAccepts negative start (counts from the end)Does not accept negative start or endBehavior with Negative IndexIf start is negative, it's treated as str.length + start. If length is negative, it's ignored.If either start or end is negative, they are treated as 0.Handling Omitted ParametersIf length is omitted, extracts characters to the end of the string.If end is omitted, extracts characters to the end of the string. Comment More infoAdvertise with us Next Article Check for Substring in JavaScript P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-string JavaScript-Questions Similar Reads Difference between String.slice and String.substring in JavaScript These 2 functions are quite similar in their Syntax But are different in some cases. Let's see the difference between them. JavaScript slice() Method:This method selects the part of a string and returns the selected part as a new string. Start and end parameters are used to specify the extracted par 3 min read Difference between String.slice and String.substring in JavaScript These 2 functions are quite similar in their Syntax But are different in some cases. Let's see the difference between them. JavaScript slice() Method:This method selects the part of a string and returns the selected part as a new string. Start and end parameters are used to specify the extracted par 3 min read Difference between String.slice and String.substring in JavaScript These 2 functions are quite similar in their Syntax But are different in some cases. Let's see the difference between them. JavaScript slice() Method:This method selects the part of a string and returns the selected part as a new string. Start and end parameters are used to specify the extracted par 3 min read Check for Substring in JavaScript Given two strings, check if one string is substring of another."bce" is substring of "abcde""ae" is not substring of "abcde"Empty String is a substring of all stringsUsing includes() - Most used and Simplest MethodThe includes() method checks whether a string contains a substring. JavaScriptlet s = 2 min read Check for Substring in JavaScript Given two strings, check if one string is substring of another."bce" is substring of "abcde""ae" is not substring of "abcde"Empty String is a substring of all stringsUsing includes() - Most used and Simplest MethodThe includes() method checks whether a string contains a substring. JavaScriptlet s = 2 min read Check for Substring in JavaScript Given two strings, check if one string is substring of another."bce" is substring of "abcde""ae" is not substring of "abcde"Empty String is a substring of all stringsUsing includes() - Most used and Simplest MethodThe includes() method checks whether a string contains a substring. JavaScriptlet s = 2 min read Like