A few days ago, I was working on building a countdown timer in JavaScript, and I needed to format my seconds and milliseconds. I wanted the seconds to always be a length of 2 digits and the milliseconds to always be a length of 3 digits. In other words I wanted 1 second to display as 01 and 1 millisecond to display as 001 .
I ended up writing my own function to “pad” these numbers, but I found out there are built in functions in JavaScript, padStart() and padEnd() to do just that. In this article, let’s look at how to leverage these built-in functions in JavaScript!
#javascript #programming #padstart #padend