Padding
Filling a string with specific characters to reach a desired length. Implemented with padStart and padEnd methods.
Padding is the process of filling a string with specific characters (typically spaces or zeros) at the beginning or end to reach a desired length. It is frequently used for tabular data formatting and code generation.
JavaScript introduced padStart() and padEnd() in ES2017. For example, '5'.padStart(3, '0') returns '005'. JavaScript practical technique books demonstrate padding use cases.
Zero-padding is especially important for date and time formatting (01, 09, etc.). Space padding is also used for table display with monospaced fonts and log output formatting.
Padding strings containing full-width characters requires extra care, as display width differs from character count. Full-width characters occupy two character widths, so simple character-count-based padding won't align properly. Data formatting books cover multilingual padding techniques.