Course contentsShow
← JavaScript
Lesson 37 of 2,7232. Values and TypesFree lesson

String: Sequences of Characters

Discover how strings represent text as immutable sequences of UTF-16 code units.

String: Sequences of Characters

You'll learn: How JavaScript strings represent text and what "immutable sequence of UTF-16 code units" means in plain English.

What is a String?

A string is JavaScript's way of storing text. Think of it like a necklace of beads where each bead is a single character—letters, numbers, punctuation, spaces, or even emoji. You create strings by wrapping text in quotes:

"Hello, World!"
'JavaScript'
"42"  // This is text, not the number 42

You can use single quotes ('...') or double quotes ("..."), but they must match on both ends.

Sequences of Characters

Strings are sequences, meaning the order matters. "cat" and "act" contain the same letters but are completely different strings because the sequence is different. JavaScript remembers every character in the exact order you typed them.

UTF-16 Code Units

Under the hood, JavaScript stores each character as a UTF-16 code unit—basically a number that represents that character in computer memory. You don't need to worry about this detail yet, but it's why JavaScript can display letters from any language, not just English.

Immutable Means "Can't Be Changed"

Once you create a string, you cannot modify it. If you have "hello" and want "Hello", JavaScript doesn't change the original—it creates a brand new string. Think of strings as being carved in stone: you can read them, copy them, or create new ones, but you can't edit the original.

"frozen"  // This string will always be "frozen"

Key Takeaway: Strings are JavaScript's primitive type for representing text as ordered sequences of characters, and once created, they cannot be changed—they are immutable.