Loading...
Loading...
Text manipulation. Immutable sequences of characters.
Learn Strings in JavaScript: covering String Basics, Template Literals, String Methods, Immutability with interactive visual examples and step-by-step explanations.
JavaScript's core data structures are arrays (ordered lists accessed by index) and objects (key-value records accessed by name). Almost all real-world data, such as a list of products, a user profile, or an API response, is some combination of the two, so creating, reading, updating, and looping over them is essential for any project.
This module covers array methods like map and filter, object property access, destructuring assignment, the spread operator, and JSON: the format every REST API speaks. Visual memory diagrams show how references and copies behave so you avoid common mutation bugs.
Understanding strings is essential for every JavaScript developer. It shows up in frontend UI code, backend APIs, and framework internals, and getting it wrong leads to bugs that are hard to trace. This chapter builds intuition with visuals so the behavior sticks.
Three ways to create. All are immutable.
const a = "double quotes"; const b = 'single quotes'; const c = `template literal`;
Each character has a zero-based index. Strings are like read-only arrays of characters.
Interpolation, multi-line, and tagged templates.
const name = "World"; const greeting = `Hello, ${name}!`; // "Hello, World!"
Backtick strings allow embedded expressions with ${...}
Transform, search, and extract.
.toUpperCase()HELLO, WORLD!.toLowerCase()hello, world!.trim()Hello, World!.split(', ')["Hello","World!"].includes('World')true.replace('World', 'JS')Hello, JS!.slice(0, 5)Hello.length13Strings never change. Methods return new strings.
let str = "Hello"; str[0] = "J"; // ✗ silently fails str.toUpperCase(); // returns "HELLO" console.log(str); // still "Hello" // To change, reassign: str = "J" + str.slice(1); // "Jello"
Every string method creates a new string. The original is never modified.
Common questions about strings.