JavaScript strings are immutable primitives with a rich set of built-in methods. Template literals (backticks) enable interpolation, multi-line strings, and tagged templates for custom processing.
includes(), slice(), replace(), replaceAll(), split(), trim(), padStart() — all return new strings (immutable)
Strings cannot be modified in place; every method returns a new string; compared by value unlike objects
Backtick strings with ${expression} interpolation, multi-line support, and any embedded expression
Pass template literals to functions for custom processing — used in styled-components, i18n, HTML escaping
Built-in tag that returns raw string without processing escape sequences — String.raw`\n` gives literal backslash-n
Strings are one of JavaScript's most commonly used types. They are immutable primitives — every string method returns a new string rather than modifying the original. ES6 introduced template literals as a major improvement over string concatenation.
includes(str) returns boolean, indexOf(str) returns position (-1 if not found), startsWith(str) and endsWith(str) check prefixes/suffixes.slice(start, end) extracts a section (supports negative indices counting from the end), substring(start, end) is similar but doesn't support negatives.toUpperCase(), toLowerCase(), trim() (removes whitespace from both ends), trimStart(), trimEnd(), padStart(length, char), padEnd(length, char).replace(search, replacement) replaces the first match. replaceAll(search, replacement) (ES2021) replaces all matches. Both accept regex.split(separator) converts string to array. Array.join(separator) does the reverse.repeat(count) returns the string repeated n times.str[0] = 'X' has no effect. Every method returns a new string.'hello' === 'hello' is true, unlike objects.for...of and spread syntax: [...'hello'] → ['h','e','l','l','o'].`) instead of quotes.${expression} — no need for concatenation.\n.${a + b}, ${condition ? 'yes' : 'no'}, ${fn()}.tagFunction`Hello ${name}`.String.raw built-in tag returns the raw string without processing escape sequences: String.raw\n`` → the literal characters \n, not a newline.Key Interview Distinction: String Immutability
Strings look like they can be modified (str[0], str.length), but they are primitives and immutable. Every operation creates a new string. This is why repeated string concatenation in a loop is inefficient — each += creates a new string. Use Array.join() or template literals for building strings from many parts.
Fun Fact
Template literals were nearly left out of ES6 entirely. The TC39 committee debated for years whether backticks were the right delimiter — single and double quotes were taken, and backticks were controversial because they're hard to type on some keyboard layouts. Tagged templates were added late in the process and have enabled entirely new paradigms like GraphQL's gql`...` and Lit's html`...`.