How JavaScript Handles Text
JavaScript Strings
Strings are text. Learn how to write them, escape special characters, and combine them.
What you'll learn
- Write string literals with single, double, or backtick quotes
- Use escape sequences for special characters
- Understand that strings are immutable
A string is a piece of text — anything from a single letter to a whole book. You write strings inside quotes.
const single = 'Single quotes';
const double = "Double quotes";
const backtick = `Backticks`;
console.log(single, double, backtick); All three forms produce the same kind of value. Pick one for your project and stick with it. Modern JavaScript convention: single quotes for plain strings, backticks when you need interpolation or multi-line (covered in the Template Literals lesson).
Escape Sequences
What if you want to use a quote inside a string? Either switch quote
styles, or escape it with \.
const a = "It's a \"quoted\" word.";
const b = 'She said "hello".';
const c = `Backticks let you use 'both' "kinds" of quotes.`;
console.log(a);
console.log(b);
console.log(c); Other common escape sequences:
| Sequence | Meaning |
|---|---|
\n | newline |
\t | tab |
\\ | a literal backslash |
\" | a literal " |
\' | a literal ' |
\u{1F600} | Unicode code point (😀) |
console.log("Line 1\nLine 2\nLine 3"); Strings Are Immutable
Once you create a string, you can’t change it. Methods like toUpperCase
return a new string — they don’t modify the original.
const greeting = "hello";
const shouted = greeting.toUpperCase();
console.log(greeting); // "hello" ← unchanged
console.log(shouted); // "HELLO" Length
Every string knows how long it is.
const name = "JavaScript";
console.log(name.length); // 10 Length counts UTF-16 code units, not visible characters. Most of the time this is what you want; emoji and other multi-byte characters can return surprising lengths.
Up Next
Now that you can write strings, let’s see what you can do with them.
JavaScript String Methods →