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

let question = 'Wheres my bandit hat?';

Length Property

The .length property of a string returns the number of characters that make up the string.

let message = 'good nite';
// Output: 9
// Output: 5

String Concatenation

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

In the example, multiple strings and variables containing string values have been concatenated. After execution of the code block, 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

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.

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


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 -1 if not found.
Returns the length of a string (number of characters).
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.
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.
Breaks the string on which it called into an array of substrings, and returns the new array.
Checks whether a string begins with the specified characters. It will only return a boolean value, either true or false.
Returns a part of a string from a given starting index or between start and end index. Index starts at zero.
Convert a string to lowercase letters.
Convert a string to uppercase letters.
Remove existing whitespace from both ends of a string.
Edit this page on GitHub


Interested in helping build Docs? Read the Contribution Guide or share your feedback form.

Learn JavaScript on Codecademy