Pad a number with leading zeroes in Javascript

As far as I have been able to tell there isn’t a built-in way with Javascript to pad a number with leading zeroes to make it a fixed width like with e.g. sprintf in other programming langages. This post looks at a way to pad a number with zeroes with Javascript.