Learn JavaScript
❯ strings_regex.string_methods

Core String Methods in JavaScript

$concept

String methods transform and inspect without mutating: charAt/at index access ([] never works for writing), toUpperCase/toLowerCase case mapping, trim/trimStart/trimEnd whitespace stripping, padStart/padEnd fixed-width padding, and repeat duplication. Every one returns a new string — chaining (s.trim().toLowerCase()) builds pipelines from pure steps.

Modern additions matter: at(-1) indexes from the end (bracket indexing can't go negative), and padStart powers zero-filled IDs and aligned columns. Immutability makes every method safe to chain in any order.

$how it works
1

Access with charAt/at

s.charAt(0) and s.at(-1) (last character) — at() handles negatives, brackets don't.

2

Case mapping

toUpperCase/toLowerCase return converted copies — locale quirks (Turkish i) need toLocale variants.

3

Trim and pad

trim() strips both ends; padStart(8, "0") left-pads to width — IDs, clocks, and tables.

4

Chain purely

s.trim().toLowerCase().replace(...) — each step returns fresh text, original untouched throughout.

$example
let s = " Ada ";
console.log(s.trim().toUpperCase());
console.log("7".padStart(3, "0"));
Output
ADA
007
1trim strips surrounding spaces, toUpperCase maps to ADA — chained pure steps.
2padStart pads "7" to width 3 with zeros — 007 for IDs and clocks.
3Originals unchanged — both results are fresh strings.
$use cases
Normalizing user input (trim + case-fold) before validation
Zero-padded IDs, timestamps, and aligned numeric columns
Last-character access with at(-1) instead of length arithmetic
Chained cleanup pipelines on imported text

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.