const number = 5;
console.log(number.toString().padStart(2, '0')); // expected output: "05"
('0' + 11).slice(-2) // '11'
('0' + 4).slice(-2) // '04'
const str1 = '5';
console.log(str1.padStart(2, '0')); // expected output: "05"
function checkTime(i) {
if (i<10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
var str = "5";
alert(str.lpad("0", 4)); //result "0005"
var str = "10"; // note this is string type
alert(str.lpad("0", 4)); //result "0010"
('0' + deg).slice(-2)
function pad(num, size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}