Learn the concept
Strings
Key string methods include: length, indexOf/includes for searching, slice/substring for extracting, toUpperCase/toLowerCase for case, trim for whitespace, split for converting to arrays, replace/replaceAll for substitution, and template literals for interpolation.
Strings in JavaScript are immutable — all methods return a new string.
Searching:
includes(str) — returns booleanindexOf(str) — returns position or -1startsWith(str) / endsWith(str)Extracting:
slice(start, end) — extracts a section (supports negative indices)substring(start, end) — similar but no negative indicescharAt(index) or bracket notation str[0]Transforming:
toUpperCase() / toLowerCase()trim() / trimStart() / trimEnd()padStart(len, char) / padEnd(len, char)repeat(count)Replacing:
replace(search, replacement) — first occurrencereplaceAll(search, replacement) — all occurrencesSplitting/Joining:
split(separator) — string → arrayArray.join(separator) — array → stringTemplate Literals:
${expression} for interpolationconst str = ' Hello, World! ';
// Searching
str.includes('World'); // true
str.indexOf('World'); // 9
str.startsWith(' He'); // true
// Extracting
str.trim(); // 'Hello, World!'
str.slice(2, 7); // 'Hello'
str.trim().slice(-6); // 'World!'
// Transforming
'hello'.toUpperCase(); // 'HELLO'
'5'.padStart(3, '0'); // '005'
// Replacing
'aabbcc'.replace('b', 'x'); // 'aaxbcc'
'aabbcc'.replaceAll('b', 'x'); // 'aaxxcc'
// Split and join
'a,b,c'.split(','); // ['a', 'b', 'c']
['a', 'b', 'c'].join('-'); // 'a-b-c'Converting titles to URL-friendly slugs using toLowerCase, replace, and trim
Using includes and indexOf for real-time search filtering of lists as users type
Trimming whitespace and normalizing user input before processing or submitting to an API
Build a utility that converts any string to a URL-friendly slug with proper character handling
Build a tool with find/replace, case conversion, word counting, and character statistics