JS Built-ins
StringString.prototype.padStartbeginner

String.prototype.padStart() β€” space padding (default)

πŸ“– Usage Example
'5'.padStart(3, '0')       // β†’ '005'
'hi'.padStart(5, '-')     // β†’ '---hi'
'hello'.padStart(3)       // β†’ 'hello'

Use padStart() to pad the beginning of a string with a fill character until it reaches the target length.

String.prototype.padStart() β€” Default Space Fill

Without a second argument, .padStart() pads with spaces.

Challenge: Implement rightAlign(str, width) that right-aligns text by padding with spaces.

rightAlign('42', 6) // β†’ '    42'
πŸ’‘ Hints (1)
  • β€’ `.padStart()` without a fill string uses space characters.