Typorithm · easy

trim, pad, includes

string-pad-trimcollectionstrimpadincludes
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn trim, pad, includes

0%

String Methods

trim strips surrounding whitespace; padStart and padEnd grow a string to a target length with a fill character. includes, startsWith, and toUpperCase test and normalize strings for reliable comparison.

trim removes leading and trailing whitespace, the first step in normalizing user input before comparing or storing it.

padStart(length, fill) and padEnd(length, fill) grow a short string to a fixed width — padStart(5, "0") turns "42" into "00042". The fill defaults to a space.

includes(sub), startsWith(prefix), and endsWith(suffix) return booleans for membership tests, while toUpperCase (and toLowerCase) normalize case so comparisons ignore it.

01

trim strips leading and trailing whitespace.

02

padStart and padEnd grow a string to a target length.

03

includes and startsWith return booleans for tests.

const clean = "  hi  ".trim()
const id = "42".padStart(5, "0")
const cell = "x".padEnd(5)
const has = "needle".includes("dle")
const starts = "needle".startsWith("nee")
const loud = "needle".toUpperCase()

Read the implementation

Connect each part of the code to the concept before you type.

1. Strip whitespace

trim removes leading and trailing whitespace, leaving "hi".

"  hi  ".trim()

2. Pad the front

padStart adds the fill at the start until the string reaches length 5, giving "00042".

"42".padStart(5, "0")

3. Pad the end

padEnd appends spaces (the default fill) until length 5, giving "x ".

"x".padEnd(5)

4. Test for substring

includes returns true when the substring appears anywhere in the string.

"needle".includes("dle")

5. Test the prefix

startsWith returns true only when the string begins with the given prefix.

"needle".startsWith("nee")

6. Normalize case

toUpperCase returns an upper-cased copy — handy for case-insensitive comparison.

"needle".toUpperCase()

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

trim, pad, includes: Lesson & Practice · Typorithm | ApplyDjinn