Categories
JavaScript Answers

How to call JavaScript parseInt() with strings with leading zeros?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *