Sometimes, we want to call JavaScript parseInt() with strings with leading zeros.
In this article, we’ll look at how to call JavaScript parseInt() with strings with leading zeros.
How to call JavaScript parseInt() with strings with leading zeros?
To call JavaScript parseInt() with strings with leading zeros, we call it with 10 as the 2nd argument.
For instance, we write
const n = parseInt("09", 10);
to call parseInt
with '09'
and 10 to parse '09'
into a decimal number.
Therefore n
is 9.
Conclusion
To call JavaScript parseInt() with strings with leading zeros, we call it with 10 as the 2nd argument.