ES6 New String Methods Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In ES6, four new methods were added to String. These methods are like a boon for programmers when it comes to string manipulation in JavaScript. In day to day programming, we often deal with strings. The first three methods also reduce the dependency on Regular Expression RegExp for certain tasks. Four ES6 New String Methods are described below: startsWith( queryString, position ) Method: This method returns either true, if the string starts with the provided string from the specified position, otherwise false. This method is case-sensitive. This method accepts two arguments : queryString: The string which has to be searched at the beginning of the String. position (optional): The position from where the search has to be start. Please note that its default value is 0. Below example illustrates the first method of ES6 New String Methods (startsWith(queryString, position)). Example: javascript < script > let str = "GeeksforGeeks"; console.log(str.startsWith("Geeks")); // Here specified position is 5, that means // searching will start from 'f' whose index // in string str is 5 console.log(str.startsWith("for", 5)); console.log(str.startsWith("geeks")); < /script> Output: true true false endsWith( queryString, length ) Method: This method returns either true, if the string ends with the provided string for specified length, otherwise false. This method is case-sensitive. This method accepts two arguments: queryString: The string which has to be searched at the end of the String. length (optional): The length of the string. Please note that its default value is length of the string. Below example illustrates the second method of ES6 New String Methods (endsWith(queryString, length)). Example: javascript <script> let str = "GeeksforGeeks"; console.log(str.endsWith("Geeks")); // Here specified length is 8, that means // length of str will be considered as 8 // and rest will be omitted console.log(str.endsWith("for", 8)); console.log(str.endsWith("geeks")); </script> Output: true true false includes( queryString, position ) Method: This method returns either true if the string is present in the provided string, otherwise returns false. This method is case-sensitive. This method accepts two arguments: queryString: The string which is to be searched in the String. position (optional): The position from where the search has to be start. Please note that its default value is 0. Below example illustrates the third method of ES6 New String Methods (includes(queryString, position)). Example: javascript <script> let str = "GeeksforGeeks"; console.log(str.includes("eks")); // Here search will start from index 8 // of str console.log(str.includes("for", 8)); console.log(str.includes("geeks")); </script> Output: true false false repeat( count ) Method: This method accepts single argument which is an integer value that represents the number of times the string is to be repeated. This method returns the newly created string with 'count' times repeated old string. Note: The argument provided i.e. count must be an positive integer. Below example illustrates the fourth method of ES6 New String Methods (repeat(count)). Example: javascript <script> let str = "GeeksforGeeks"; console.log(str.repeat(2)); let newStr = str.repeat(3); console.log(newStr); </script> Output: GeeksforGeeksGeeksforGeeks GeeksforGeeksGeeksforGeeksGeeksforGeeks Template Literals: These literals allowed embedded expression. Single or double quotes are not it's behavior rather that it used back-ticks "`". There are two types of Template Literals. Singleline Strings and Template Literals: The Singleline Strings and Template Literals contains the single line string below example will illustrate this. Example: javascript <script> var a = "Geeks"; var b = "for"; console.log(`We are the ${a+b+a} `) </script> Output: We are the GeeksforGeeks Multiline Strings and Template Literals: This Multiline Strings and Template Literals contains the multi-line string below example will illustrate this. Example: javascript <script> var a = `GeeksforGeeks`; var b = ` A Online Computer Science Portal for Geeks`; console.log(a + b) </script> Output: GeeksforGeeks A Online Computer Science Portal for Geeks String.raw() Method: The String.raw() method is used to print the backslash as it is and it does not bring the new line into the console. Example: javascript <script> var geeks = String.raw `A Online Computer \nScience Portal for Geeks` //Printing backslash as string console.log(geeks) </script> Output: A Online Computer \nScience Portal for Geek String.fromCodePoint() Method: The String.fromCodePoint() is an inbuilt function in JavaScript which is used to return a string or an element for the given sequence of code point value (ASCII value). Example: javascript <script> // Taking some code point values a = String.fromCodePoint(42); b = String.fromCodePoint(66, 65, 102); // Printing the corresponding elements of // the code point value. console.log(a + "<br>") console.log(b) </script> Output: * BAf Create Quiz Comment I iamvineettiwari Follow 0 Improve I iamvineettiwari Follow 0 Improve Article Tags : JavaScript Web Technologies ES6 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