Strings
Text & String Methods
Strings are sequences of characters representing text. JavaScript provides 20+ built-in methods to search, transform, extract, and format text data.
A string is like a bead necklace - each bead is one character. You can count the beads (.length), pick a specific bead (.charAt), cut a section (.slice), join two necklaces (+), or repaint the whole thing (.toUpperCase).
🔑 Key Concepts
Single quotes, double quotes, or backtick template literals. Backticks allow expressions with ${}.
20+ built-in methods: toUpperCase, slice, indexOf, includes, replace, split, trim, repeat and more.
Backtick strings allow multi-line text and embedding variables/expressions using ${ } syntax.
💻 Code Examples
⚠️ Common Mistakes
Forgetting string methods return NEW strings
Strings are immutable! let upper = str.toUpperCase(); - always save the result.
Using + for complex string building
Use template literals (backticks) for cleaner, more readable interpolation.
indexOf returns -1 when not found - not falsy!
-1 is truthy! Use includes() for simple true/false checks instead of indexOf.
📋 Quick Reference
Live Code Playground
Edit the code and press ▶ Run to see output instantly.