Example 1 — Leading Zeros and Default Spaces
Pad on the left with "0" or the default space.
console.log("5".padStart(3, "0")); // "005"
console.log("200".padStart(5)); // " 200" How It Works
- Measure the gap.
"5"has length1; target is3→ need2chars. - Prepend the filler. Two
"0"characters make"005". - Default is space. Omitting
padStringpads"200"with two spaces on the left. - New string only. The originals stay unchanged.

