String.prototype.padStartintermediate'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.
Zero-padding is great for time values like hours and minutes.
Challenge: Implement formatTime(h, m) that formats hours and minutes as HH:MM.
formatTime(9, 5) // β '09:05'
formatTime(12, 0) // β '12:00'