This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.

Smartphone icons created by Freepik - Flaticon

JavaScript Strings

The padStart() Method

The padStart() method pads a string from the start.

It pads the string with another string (multiple times) until it reaches a given length.

let numb = 5;
let text = numb.toString();
document.getElementById("demo").innerHTML = text.padStart(4,0);
Legend

number convert number to string new string