javascript print int with leading zeros

JavaScript
function padLeadingZeros(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}
padLeadingZeros(57, 3);// "057"
padLeadingZeros(57, 4); //"0057"
Source

Also in JavaScript: