Core String Methods in JavaScript
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.
Access with charAt/at
s.charAt(0) and s.at(-1) (last character) — at() handles negatives, brackets don't.
Case mapping
toUpperCase/toLowerCase return converted copies — locale quirks (Turkish i) need toLocale variants.
Trim and pad
trim() strips both ends; padStart(8, "0") left-pads to width — IDs, clocks, and tables.
Chain purely
s.trim().toLowerCase().replace(...) — each step returns fresh text, original untouched throughout.
let s = " Ada ";console.log(s.trim().toUpperCase());console.log("7".padStart(3, "0"));Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.