JSFiddle - React, Tailwind, and code Playground
addLeadingZero
JavaScript
function addLeadingZero(n, totalDigits)
{
if(!totalDigits)totalDigits > 1;
n = String(n);
while (n.length < totalDigits)
n = "0"+n;
return n;
}
var num = 5;
num = addLeadingZero(num, 2);
alert (num);