Book spine labels: padStart and padEnd fill up to a target length, the pad tiles coloured. And what about a value already longer than the target? An…
Why it matters
Leading zeros, lined-up columns, masks: they show up all over a UI (clocks, invoices, tables, IDs). Without padding, people write their own logic, prone to off-by-one. padStart/padEnd is one clear, correct line.
The key idea
Padding fills up to a TARGET length, not N more characters
Try it in this playground
Value 5, target 2, pad '0' padStart gives 05 (a digital clock), padEnd gives 50. A different side, a different result.
Raise the target to 6 or more More pad goes in until the length fits. The first argument is the FINAL length.
Use a two-character pad, like '.-' The pad repeats, then is cut right at the target, so its end can be half the pattern.
Make the value longer than the target The result is the value itself: padding never cuts. The target line on the board falls among the tiles.