Skip to main content
Module 2 · Lesson 2 of 46/32 in the course~16 min
Module lessons (2/4)

String methods

Lesson preview5 hands-on exercises readyJavaScript Course · Module 2 — Strings and numbers

length, toUpperCase, includes, slice, split, replace: the methods you use every day.

What you'll learn in this lesson

  • Take advantage of the main search and inspection methods (includes, startsWith, endsWith, indexOf, length).
  • Extract and normalize user text with slice, trim, toLowerCase / toUpperCase.
  • Split strings into arrays with split and reassemble them with join.
  • Understand why all string methods are non-mutant and require reassignment or chaining.

Overview

Strings in JavaScript are immutable: no method alters the starting string, but they all return a new string (or a boolean, an index or an array). This makes them ideal for building normalization pipelines by chaining multiple calls together.

Just like in array pipelines, you can break text with .split(), clean up the elements, and rejoin them without mutating the original text.

Sections covered in this lesson

  1. 1Mental model: non-mutant pipeline on strings
  2. 2Progressive examples
  3. 3Guided laboratory
  4. 4Check for understanding
Pro Lesson · Module 2 — Strings and numbers

Unlock "String methods" and the full JavaScript Course curriculum

length, toUpperCase, includes, slice, split, replace: the methods you use every day.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in JavaScript Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.