JavaScript Tutorial: Strings & Template Literals
Master JavaScript strings — methods, template literals, formatting, and all the tricks you'll use every day.
Strings are everywhere
Names, emails, URLs, messages, code — everything is strings. JavaScript strings come with a large built-in toolbox of methods that you will reach for constantly.
Template literals (backtick strings) are the crown jewel — expressions inside `${}` make formatting effortless.
What you'll learn in this JavaScript strings & template literals tutorial
This interactive JavaScript tutorial has 10 hands-on exercises. Estimated time: 20 minutes.
- Template literals — the modern way — Backtick strings are the gold standard for building strings in modern JavaScript. They support:
- length and indexing — Strings have a `length` property and you can access characters by index (0-based):
- toUpperCase, toLowerCase, trim — Three methods you will use constantly:
- includes, startsWith, endsWith — Search inside strings:
- slice — extract a portion — `.slice(start, end)` extracts a substring:
- split and join — `.split(separator)` breaks a string into an array.
- replace and replaceAll — `.replace(search, replacement)` replaces the **first** match.
- padStart, padEnd, repeat — String padding and repetition — used for formatting aligned output:
- indexOf and search — Find the position of something in a string:
- Build a string formatter — Final challenge — no starter code.
JavaScript Strings & Template Literals concepts covered
- Strings are everywhere