Add leading zeros to a number in JavaScript

Published on 2023-01-14 · JavaScript Programming

As I was looking for a more subtle solution for inserting leading zeros to a number than if (number < 10) return `0${number}`;, I found this answer on StackOverflow, which I want to expand to near-one line code snippet.