Learn JavaScript
❯ types.strings

Strings in JavaScript

$concept

Strings are immutable UTF-16 sequences in single, double, or backtick quotes — quote choice is style except that backticks enable interpolation. Indexing (s[0]), length, and iteration all operate on UTF-16 code units, which splits astral characters (emoji) in two — [...s] spreads by code point when that matters.

Every string method returns a new string; the original never changes. Concatenation with + is fine for a few pieces; hot loops should collect into arrays and join once instead of quadratic += chains.

$how it works
1

Three quote styles

Single, double (interchangeable), backticks (interpolation + multiline) — pick per team style, backticks when embedding values.

2

Immutable always

s[0] = "X" silently fails (or throws strict) — methods like toUpperCase return fresh strings.

3

UTF-16 under the hood

length counts code units, so emoji count 2 — spread ([...s]) or Array.from for code-point-correct iteration.

4

Build efficiently

Few pieces: + is fine. Many pieces in a loop: push to an array, join("") once at the end.

$example
let s = "hello";
console.log(s.length, s[1]);
console.log(s.toUpperCase(), s);
Output
5 e
hELLO hello
1length reports 5 code units; s[1] reads (never writes) the second character e.
2toUpperCase returns hELLO while s itself still prints hello — immutability demonstrated.
3Method results must be captured — calling without using the return changes nothing.
$use cases
Choosing backticks the moment a value interpolates
Spreading emoji text correctly with [...s] instead of split("")
Joining loop-built strings via array push + join
Never assigning to string indexes (silent no-op outside strict mode)

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.