Difference between substr() and substring() in JavaScript Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 1 Likes 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. Create Quiz Comment P PranchalKatiyar Follow 1 Improve P PranchalKatiyar Follow 1 Improve Article Tags : JavaScript Web Technologies javascript-string JavaScript-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like