GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — JavaScript Strings - GeeksforGeeks JavaScript StringsLast Updated : 11 Jun, 2026 A JavaScript String is a sequence of characters, typically used to represent text.
Create using Literals - RecommendedWe can either use a single quote or a double quote to create a string. We can use either of the two, but it is recommended to be consistent with your choice throughout your code.
Create using ConstructorThe new String() constructor creates a string object instead of a primitive string. It is generally not recommended because it can cause unexpected behavior in comparisons
Template Literals (String Interpolation)You can create strings using Template Literals. Template literals allow you to embed expressions within backticks (`) for dynamic string creation, making it more readable and versatile.
Empty StringYou can create an empty string by assigning either single or double quotes with no characters in between.
Since the strings are empty, console.log will print two blank lines. Multiline Strings (ES6 and later)You can create a multiline string using backticks (``) with template literals. The backticks allows you to span the string across multiple lines, preserving the line breaks within the string.
Basic Operations on JavaScript Strings1. Finding the length of a String You can find the length of a string using the length property.
You can combine two or more strings using + Operator.
We can use escape characters in string to add single quotes, dual quotes, and backslash. \' - Inserts a single quote
Using a backslash (\) to break a long string is not recommended, as it is not supported in strict mode. Instead, use template literals or string concatenation.
We can extract a portion of a string using the substring() method.
Convert a string to uppercase and lowercase using toUpperCase() and toLowerCase() methods.
Find the first index of a substring within a string using indexOf() method.
Replace occurrences of a substring using the replace() method. By default, replace() only replaces the first occurrence. To replace all occurrences, use a regular expression with the g flag.
Remove leading and trailing whitespaces using trim() method.
Access individual characters in a string using bracket notation and charAt() method.
There are some inbuilt methods that can be used to compare strings such as the equality operator and another like localeCompare() method.
12. Passing JavaScript String as Objects We can create a JavaScript string using the new keyword.
Are the strings created by the new keyword is same as normal stringsNo, the string created by the new keyword is an object and is not the same as normal strings.
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |