Strings hold almost every piece of text in JavaScript — names, messages, URLs, and JSON. This hub links to 51 live tutorials today and catalogs 52 String methods for search, slice, trim, replace, padding, and validation.
01
Immutable
Never mutate
02
Search
includes / indexOf
03
Extract
slice / split
04
Transform
trim / case
05
Template
`${value}`
06
52 methods
Full index
Fundamentals
Introduction
A JavaScript string is an ordered sequence of characters used for names, messages, file paths, and API payloads. You create them with quotes, template literals, or String() — then call methods to search, slice, and format text without writing character-by-character loops.
What Are String Methods?
String methods live on String.prototype and are available on every string primitive through auto-boxing. Groups include search & test (includes, startsWith, indexOf), extract & split (slice, split), transform (trim, toUpperCase, padStart), and replace (replace, replaceAll). Every method returns a new string — originals never change.
💡
Beginner Tip
Prefer string primitives ("hello") over new String("hello") object wrappers. Primitives are faster, compare predictably with ===, and still expose all prototype methods.
Primitives vs String Objects
Primitive — const name = "Alex"; — the normal, recommended form.
Object wrapper — new String("Alex") — rare; typeof returns "object".
Auto-boxing — JavaScript temporarily wraps primitives when you call name.trim().
Template Literals vs Concatenation
Template literals — `Hello, ${name}!` — interpolation and multiline text.
Plus operator — "Hello, " + name + "!" — fine for short joins.
concat() — "Hello, ".concat(name, "!") — explicit but less common today.
Foundation
📝 Syntax
Common string patterns — note each call returns a new value:
Search by name or browse by category. Each tutorial includes syntax, five try-it examples, and FAQs. The catalog covers 52 methods — 49 method tutorials live now plus 3 properties.
String Properties
3 tutorials
Core String object properties every beginner should know first.
Open DevTools Console (F12) and paste each snippet. Remember: every method returns a new string.
📚 Transform & Chain
Immutable pipelines that build new strings step by step.
Example 1 — Chain toUpperCase(), replace(), and slice()
Normalize text, swap a word, then take a short preview — without mutating the source.
JavaScript
const raw = " hello world ";
const result = raw
.trim()
.toUpperCase()
.replace("WORLD", "JavaScript")
.slice(0, 11);
console.log(result); // "HELLO JAVAS"
console.log(raw); // still " hello world "
split() breaks a string into an array; Array.prototype.join() stitches it back. Pair this pattern with the Array hub when you need map or filter in between.
🛠 Clean & Format
Whitespace cleanup and fixed-width display.
Example 4 — Trim User Input
Remove accidental spaces before comparing or saving form data.
padStart(targetLength, fillString) repeats the fill character on the left until the string reaches the desired length. Combine with template literals for readable labels.
Tips
💬 Usage Tips
Assign results — text = text.trim(); calling trim() alone does nothing unless you store the return value.
Prefer slice over substr — substr() is legacy; slice() supports negative indexes from the end.
Case-insensitive checks — normalize with toLowerCase() before includes() when comparing user input.
Emoji-aware length — length counts UTF-16 code units; use [...str].length or codePointAt() when grapheme count matters.
Search this index — jump to any of 51 live tutorials or scan the 52-method catalog above.
Watch Out
⚠️ Common Pitfalls
Expecting mutation — str.toUpperCase() without assignment leaves str unchanged.
String object confusion — new String("a") === new String("a") is false (different objects).
Emoji length — "😀".length === 2 surprises beginners; plan for surrogate pairs in UI limits.
replace vs replaceAll — replace() swaps only the first match unless you pass a global regex.
Sort as strings — "10" < "2" lexically; parse numbers before comparing when needed.
🧠 How String Methods Work
1
Primitive value
Text lives as an immutable UTF-16 sequence — literals, templates, or String().
Create
2
Auto-box & call
JavaScript temporarily wraps the primitive to reach String.prototype methods.
Invoke
3
New string returned
Search, slice, trim, and replace produce fresh strings — chain or assign the result.
Transform
=
📄
Reliable text handling
Validate input, format output, and integrate with arrays and regex — without manual character loops.
Compatibility
Browser Support
Core String methods like slice, trim, split, and includes are supported in every modern browser and Node.js. Newer helpers such as replaceAll, padStart, and at are widely available in current engines.
✓ Baseline · ES3+ / ES2015+
String.prototype methods
Supported in Chrome, Firefox, Safari, Edge, and all maintained Node.js releases. Locale methods depend on the host Intl implementation; UTF-16 length behavior is consistent everywhere.
100%Core API
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
String methodsUniversal
Bottom line: Production-safe across modern environments. Use feature checks only for very new APIs like replaceAll in legacy browsers, or polyfill when supporting IE11.
Wrap Up
🎉 Conclusion
JavaScript strings are immutable text values with a rich toolkit for search, extraction, transformation, and formatting. Start with properties like length, then chain trim(), slice(), and template literals in real code.
Use the searchable index for 51 live tutorials today and the full 52-method catalog as new pages ship — each includes try-it labs and FAQs.
String methods are functions on String.prototype (or the String constructor for static helpers) that search, extract, transform, and format text. Examples include slice(), trim(), split(), replace(), includes(), and padStart(). They always return new values — strings never mutate in place.
No. Strings are immutable. Methods like toUpperCase() and replace() return a new string; the original stays the same. To update a variable, assign the result: text = text.trim().
A primitive like "hello" is the normal, lightweight form. new String("hello") wraps text in an object — rarely needed and can confuse typeof checks. Prefer primitives and let JavaScript auto-box them when you call methods.
JavaScript strings use UTF-16 code units. Many emoji and rare characters occupy two code units (a surrogate pair). Use codePointAt(), [...str], or Intl.Segmenter when you need true grapheme counts.
Template literals (backticks) are the modern default — they support interpolation (${name}) and multiline text. Use + or concat() for simple joins when you prefer, but backticks are clearer for dynamic messages.
Read the overview, try the five examples, then open the String constructor from Properties. Use the search box to browse 51 live tutorials and the full catalog of 52 String methods.
Did you know?
When you write "hello"[0], JavaScript coerces the primitive to a String object, reads index 0, then discards the wrapper. Bracket access is convenient, but charAt() and at() make intent clearer in tutorials.