Example 1 — Basic Right Padding
Pad with dots or the default space until a target length.
console.log("hi".padEnd(5, ".")); // "hi..."
console.log("200".padEnd(5)); // "200 " How It Works
- Measure the gap.
"hi"has length2; target is5→ need3chars. - Append the filler. Three
"."characters make"hi...". - Default is space. Omitting
padStringpads"200"with two spaces to length5. - New string only. The originals stay unchanged.

