Published Jul 30, 2021Updated Dec 4, 2023
Contribute to Docs

Strings are a primitive data type. They are any grouping of characters (letters, spaces, numbers, or symbols) surrounded by single quotes ', double quotes " or backticks `.


In JavaScript, multiple strings can be concatenated or joined together using the + operator.

In the example below, multiple strings and variables containing string values have been concatenated. After the code block is run, the displayText variable will contain the concatenated string:

let service = 'credit card';
let month = 'May 30th';
let displayText = 'Your ' + service + ' bill is due on ' + month + '.';
// Output: Your credit card bill is due on May 30th.


String interpolation is the process of evaluating string literals containing one or more placeholders (expressions, variables, etc). It can be performed using template literals (text ${expression} text), as in the following example:

let age = 7;
// String concatenation
'Tommy is ' + age + ' years old.';
// String interpolation
`Tommy is ${age} years old.`;

Escaping Characters

On occasion in may be necessary to include characters in a string that may have reserved meanings or to apply additional formatting. Characters, such as quotes, can be included by prepending a \. There are a number of predefined escape sequences such as \n or \t to add formatting such as a line break or tab respectively.

// Line break
// Output:
// Hello
// World
// Escaping a quote
console.log("Wayne's World");
// Output: Wayne's World


Returns a single character at the specified index of a string.
Concatenates or combines strings together.
Returns true if a given value is included in a string.
Searches a string for a given value and returns the first index if found.
Returns the number of characters in a string.
Repeats a string a specified number of times. String will be concatenated.
Searches a string for a string value, or a regular expression, and returns a new string where some or all matches are replaced.
Returns a new string by replacing all the matches of a given search value with a given replacement value.
Takes a regular expression argument and returns either the character position of the start of the first matching substring or -1 if there is no match.
Returns a selected portion of a string.
Returns a new array of substrings based on a given string.
Checks whether a string begins with the specified characters. It returns true if it does, otherwise false.
Returns a part of a string from a given starting index or between the start and end index. The index starts at zero.
Convert a string to lowercase letters.
Returns a string representing the object.
Convert a string to uppercase letters.
Removes existing whitespace from both ends of a string.
Returns the value of a String object as a string.

All contributors

Looking to contribute?

Learn JavaScript on Codecademy