Learn JavaScript
❯ types.template_literals

Template Literals in JavaScript

$concept

Backtick strings interpolate with ${} (any expression, coerced to string), span multiple lines preserving newlines, and power tagged templates (tag`...` hooks receiving strings plus values for SQL builders, i18n, and styled-components). Nesting works — templates inside ${} are just expressions.

Escaping is minimal: backslash escapes backticks (\`) and ${ (\${) when literal text is needed. For user-facing messages, templates replace nearly all + concatenation with readable, single-expression construction.

$how it works
1

Interpolate with ${}

`Hello, ${name}!` evaluates name inline — any expression allowed, coerced via String().

2

Multiline for free

Line breaks inside backticks are real newlines — no \n juggling for multi-line text.

3

Nesting is legal

`outer ${`inner ${x}`} done` — inner templates are expressions like any other.

4

Tagged templates hook in

sql`SELECT * WHERE id=${id}` passes strings+values to a tag function — safe query builders and DSLs live here.

$example
let name = "Ada";
let n = 3;
console.log(`Hello, ${name}! You have ${n} messages.`);
Output
Hello, Ada! You have 3 messages.
1Each ${} evaluates its expression and stringifies the result inline.
2The number 3 coerces to "3" automatically during interpolation.
3One readable expression replaced what + concatenation would splinter across operators.
$use cases
User-facing messages with embedded values (no + chains)
Multi-line HTML, SQL, and text blocks without escapes
Tagged templates for safe queries and styled components
Nesting templates for conditional fragments inside larger ones

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.