JavaScript String Exercises
Master JavaScript strings with interactive exercises covering string length, character access, case conversion, trimming, slicing, searching, replacing, splitting, joining, formatting, and text parsing. Write and test real code in your browser with immediate feedback.
Exercises
Work from beginner to hard, or use the filters to find a specific skill.
String Positions
Strings are ordered. The first character is at index `0`, and the last character...
String Length
`length` tells you how many characters a string contains. Spaces count because t...
Bracket Access
Bracket notation reads one character at a known position. It is useful when a st...
Lowercase Text
Programs often normalize labels before comparing or storing them. A lowercase co...
Trim Whitespace
`trim` removes whitespace from the start and end of a string. It does not remove...
Repeat Text
`repeat` creates a new string by repeating another string a chosen number of tim...
Search Inside Text
`includes` answers a yes-or-no question: does this string contain that text? Yo...
Slice From the End
`slice` can read from the end of a string with a negative start index. That is u...
Normalize Input
User-entered text often has accidental spaces and inconsistent casing. A reusabl...
Check the End
For email domains, the position of the match matters. `person@example.com` shoul...
Split a Name
When text has a reliable separator, you can split it into pieces and read the ch...
URL Slugs
A slug is a readable piece of a URL. It usually has lowercase words separated by...
Debug a Slice
`slice(start, end)` includes the start index but stops before the end index. Off...
Pick the Right Search
Two search functions can both return true for the same text while answering diff...
Pad Text
`padStart` adds characters to the front of a string until it reaches a target le...
Replace Repeated Text
When the same sensitive word can appear more than once, replacing only the first...
Extract Between Markers
Practice JavaScript string slicing by extracting text only when start and end ma...
Mask Personal Text
Mask email text with JavaScript string methods by normalizing the address and hi...
Count Repeated Text
Count JavaScript string matches by finding non-overlapping term occurrences whil...
Valid Anagram
Two words are anagrams when they use the same characters the same number of time...
Truncate Carefully
Practice JavaScript string truncation by building a summary helper that respects...
Parse a Tag List
Turn comma-separated JavaScript string input into a clean array of labels. This ...
String Methods Return New Values
Debug a JavaScript string cleanup bug where calling trim is not enough unless th...
Index Results Are Numbers
Fix a JavaScript string search bug where indexOf position numbers are treated li...
Split on the Last Marker
Practice JavaScript string indexing by splitting a filename on its final dot ins...
Render Placeholder Text
Practice JavaScript string replacement by rendering placeholder text from an obj...
Parse Query Strings
Convert URL query text with JavaScript string parsing into an object of decoded ...
Parse Quoted CSV
Walk a CSV line with JavaScript string parsing while tracking whether the curren...
Highlight Search Matches
Practice JavaScript string searching by highlighting every case-insensitive matc...
Practice JavaScript strings with real text
Strings represent text throughout JavaScript applications, from form input and usernames to messages, URLs, search terms, and API data. These JavaScript string exercises help you read, clean, search, format, compare, and parse that text with the methods developers use in everyday code.
The collection progresses from string positions, length, bracket access, case conversion, trimming, repetition, searching, and slicing into normalization, prefix and suffix checks, splitting, joining, padding, replacement, masking, counting, and careful truncation.
Later challenges turn string manipulation into realistic text-processing work: build URL slugs, extract content between markers, parse tag lists and query strings, handle quoted CSV, render placeholder text, and highlight search matches. You'll also debug common mistakes involving slice boundaries, indexOf return values, and the fact that JavaScript string methods return new values instead of changing the original string.
- Exercises
- 29
- Difficulty
- Beginner to Hard
- Good to know first
- Know how to declare variables, recognize a JavaScript string value, and read a small function.
What you’ll practice
- Read characters with indexes, bracket access, and string length
- Normalize input with trimming and case conversion
- Search text with includes, indexOf, startsWith, and endsWith
- Slice strings and extract text between markers
- Replace, repeat, pad, mask, and truncate text
- Split and join names, tags, slugs, and other text data
- Compare and count text without accidental case mismatches
- Parse query strings and CSV, render placeholders, and highlight matches
Who these exercises are for
This practice set starts with beginner-friendly string basics and develops into harder parsing and formatting challenges. It works for first-time JavaScript learners, students reinforcing a course, and developers sharpening their text-processing and debugging skills.
How practice works
- Write and run JavaScript directly in your browser
- Use instant test feedback to catch indexing and formatting mistakes
- Progress from basic string access to practical parsing challenges
- Filter exercises by difficulty and save your progress when signed in